{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c62954eb-573f-4858-9816-b46c35ecdf8b",
   "metadata": {},
   "source": [
    "# Data Collection"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e7c8a57-0839-4eda-aadc-fbcb8d27a6d0",
   "metadata": {},
   "source": [
    "## Load the Libs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a2d5a5a9-9550-4315-a363-fc831d867c65",
   "metadata": {},
   "outputs": [],
   "source": [
    "# import Lib\n",
    "import pandas as pd\n",
    "import datetime as dt\n",
    "import pytz\n",
    "import os\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import yfinance as yf\n",
    "\n",
    "# import module\n",
    "from datetime import datetime, timezone\n",
    "from datetime import date, time\n",
    "from math import trunc\n",
    "from dateutil.parser import parse"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "72db88c0-8fa6-4ffc-adf7-c67087ed749c",
   "metadata": {},
   "source": [
    "## Collecting Options Data from Yahoo Finance using \"yfinance\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a3bf29bf-80aa-4485-924c-92c072cdead1",
   "metadata": {},
   "source": [
    "### Getting AAPL underlying stock prices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "631287bb-2cc3-4b66-94d7-41eea989c875",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                 Open        High         Low       Close  \\\n",
      "Date                                                                        \n",
      "2018-05-21 00:00:00-04:00   44.916741   45.220169   44.656321   44.828342   \n",
      "2018-05-22 00:00:00-04:00   45.007523   45.126982   44.625251   44.716042   \n",
      "2018-05-23 00:00:00-04:00   44.522525   45.036199   44.381560   45.002750   \n",
      "2018-05-24 00:00:00-04:00   45.100712   45.117434   44.489080   44.952579   \n",
      "2018-05-25 00:00:00-04:00   44.971698   45.310962   44.833124   45.055321   \n",
      "...                               ...         ...         ...         ...   \n",
      "2023-05-15 00:00:00-04:00  173.160004  173.210007  171.470001  172.070007   \n",
      "2023-05-16 00:00:00-04:00  171.990005  173.139999  171.800003  172.070007   \n",
      "2023-05-17 00:00:00-04:00  171.710007  172.929993  170.419998  172.690002   \n",
      "2023-05-18 00:00:00-04:00  173.000000  175.240005  172.580002  175.050003   \n",
      "2023-05-19 00:00:00-04:00  176.389999  176.389999  174.940002  175.160004   \n",
      "\n",
      "                             Volume  Dividends  Stock Splits  \n",
      "Date                                                          \n",
      "2018-05-21 00:00:00-04:00  73603200        0.0           0.0  \n",
      "2018-05-22 00:00:00-04:00  60962800        0.0           0.0  \n",
      "2018-05-23 00:00:00-04:00  80233600        0.0           0.0  \n",
      "2018-05-24 00:00:00-04:00  92936000        0.0           0.0  \n",
      "2018-05-25 00:00:00-04:00  69844000        0.0           0.0  \n",
      "...                             ...        ...           ...  \n",
      "2023-05-15 00:00:00-04:00  37266700        0.0           0.0  \n",
      "2023-05-16 00:00:00-04:00  42110300        0.0           0.0  \n",
      "2023-05-17 00:00:00-04:00  57951600        0.0           0.0  \n",
      "2023-05-18 00:00:00-04:00  65496700        0.0           0.0  \n",
      "2023-05-19 00:00:00-04:00  55772400        0.0           0.0  \n",
      "\n",
      "[1259 rows x 7 columns]\n"
     ]
    }
   ],
   "source": [
    "import yfinance as yf\n",
    "\n",
    "# Define the ticker symbol\n",
    "mb_tickerSymbol = 'AAPL'\n",
    "\n",
    "# Get data on this ticker\n",
    "mb_tickerData = yf.Ticker(mb_tickerSymbol)\n",
    "\n",
    "# Get the historical prices for this ticker\n",
    "mb_tickerDf05192023 = mb_tickerData.history(period='5y')\n",
    "\n",
    "# See your data\n",
    "print(mb_tickerDf05192023)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "33d45fe7-50f0-4735-acfc-d8eff2bde47d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current date & time :  2023-05-21 11:06:44.380372\n",
      "~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\n",
      "File saved named:\n",
      "mb_tickerDf05192023 2023-05-21 11-06-44-380372.csv\n",
      "2023-05-21 11:06:44.380372\n",
      "~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\n"
     ]
    }
   ],
   "source": [
    "# import Lib\n",
    "import pandas as pd\n",
    "import datetime as dt\n",
    "import pytz\n",
    "import os\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# import module\n",
    "from datetime import datetime, timezone\n",
    "from datetime import date, time\n",
    "from math import trunc\n",
    "\n",
    "# get current date and time\n",
    "current_datetime = datetime.now()\n",
    "print(\"Current date & time : \", current_datetime)\n",
    "filename1 = datetime.now().strftime(\"%Y-%m-%d %H-%M-%S-%f\")\n",
    "\n",
    "# create a file object along with extension\n",
    "file_name = \"mb_tickerDf05192023 \"+filename1+\".csv\"\n",
    "#print (file_name)\n",
    "\n",
    "# converting to csv\n",
    "mb_tickerDf05192023.to_csv(file_name)\n",
    "print(\"~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\")\n",
    "print(\"File saved named:\")\n",
    "print (file_name)\n",
    "print(current_datetime)    \n",
    "print(\"~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc40bdc0-c011-44f5-b26a-b95a4ff25ecf",
   "metadata": {},
   "source": [
    "### Getting AAPL stock Options related data including Implied Volatilities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9c5f54fa-1342-4a0f-8e54-5e298fee6aa5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "           contractSymbol             lastTradeDate  strike  lastPrice  \\\n",
      "0     AAPL230526C00095000 2023-05-19 19:36:18+00:00    95.0      80.27   \n",
      "1     AAPL230526C00100000 2023-05-17 13:59:34+00:00   100.0      75.32   \n",
      "2     AAPL230526C00110000 2023-05-16 18:17:19+00:00   110.0      62.18   \n",
      "3     AAPL230526C00115000 2023-05-08 15:00:05+00:00   115.0      58.70   \n",
      "4     AAPL230526C00120000 2023-05-17 19:25:47+00:00   120.0      52.52   \n",
      "...                   ...                       ...     ...        ...   \n",
      "1628  AAPL251219P00260000 2023-05-15 18:24:01+00:00   260.0      86.91   \n",
      "1629  AAPL251219P00270000 2023-05-05 14:01:40+00:00   270.0      96.76   \n",
      "1630  AAPL251219P00290000 2023-05-11 17:03:36+00:00   290.0     116.36   \n",
      "1631  AAPL251219P00300000 2023-04-19 13:31:50+00:00   300.0     134.00   \n",
      "1632  AAPL251219P00310000 2023-05-15 18:24:01+00:00   310.0     139.21   \n",
      "\n",
      "         bid     ask    change  percentChange  volume  openInterest  \\\n",
      "0      78.95   81.45  1.269997       1.607591     7.0             0   \n",
      "1      73.50   76.50  4.639999       6.564798     1.0             6   \n",
      "2      63.50   66.55  0.000000       0.000000    13.0            13   \n",
      "3      59.10   61.55  0.000000       0.000000     1.0             3   \n",
      "4      53.60   56.95  0.000000       0.000000     6.0             5   \n",
      "...      ...     ...       ...            ...     ...           ...   \n",
      "1628   82.75   86.65  0.000000       0.000000    86.0             0   \n",
      "1629   92.75   96.65  0.000000       0.000000     1.0             0   \n",
      "1630  112.70  116.60  0.000000       0.000000    20.0             0   \n",
      "1631    0.00    0.00  0.000000       0.000000     1.0             0   \n",
      "1632  132.70  136.60  0.000000       0.000000    93.0             0   \n",
      "\n",
      "      impliedVolatility  inTheMoney contractSize currency OptionType  \\\n",
      "0              1.812501        True      REGULAR      USD       Call   \n",
      "1              2.871097        True      REGULAR      USD       Call   \n",
      "2              2.478519        True      REGULAR      USD       Call   \n",
      "3              1.539065        True      REGULAR      USD       Call   \n",
      "4              1.332035        True      REGULAR      USD       Call   \n",
      "...                 ...         ...          ...      ...        ...   \n",
      "1628           0.168923        True      REGULAR      USD        Put   \n",
      "1629           0.180520        True      REGULAR      USD        Put   \n",
      "1630           0.200753        True      REGULAR      USD        Put   \n",
      "1631           0.000010        True      REGULAR      USD        Put   \n",
      "1632           0.220070        True      REGULAR      USD        Put   \n",
      "\n",
      "     expirationDate  time_to_expiration  \n",
      "0        2023-05-26                   4  \n",
      "1        2023-05-26                   4  \n",
      "2        2023-05-26                   4  \n",
      "3        2023-05-26                   4  \n",
      "4        2023-05-26                   4  \n",
      "...             ...                 ...  \n",
      "1628     2025-12-19                 942  \n",
      "1629     2025-12-19                 942  \n",
      "1630     2025-12-19                 942  \n",
      "1631     2025-12-19                 942  \n",
      "1632     2025-12-19                 942  \n",
      "\n",
      "[1633 rows x 17 columns]\n"
     ]
    }
   ],
   "source": [
    "import yfinance as yf\n",
    "from datetime import datetime\n",
    "import pandas as pd\n",
    "\n",
    "# Define the ticker symbol\n",
    "mb_tickerSymbol = 'AAPL'\n",
    "\n",
    "# Get data on this ticker\n",
    "mb_tickerData = yf.Ticker(mb_tickerSymbol)\n",
    "\n",
    "# Get the option expirations\n",
    "mb_options_expirations = mb_tickerData.options\n",
    "\n",
    "# Prepare a list to hold all options data\n",
    "mb_options_list = []\n",
    "\n",
    "# Loop through each options expiration date\n",
    "for expiration in mb_options_expirations:\n",
    "    # Get options data for each expiration date\n",
    "    mb_options_data = mb_tickerData.option_chain(expiration)\n",
    "    \n",
    "    # Add option type and expiration date to the data\n",
    "    mb_options_data.calls['OptionType'] = 'Call'\n",
    "    mb_options_data.calls['expirationDate'] = expiration\n",
    "    mb_options_data.puts['OptionType'] = 'Put'\n",
    "    mb_options_data.puts['expirationDate'] = expiration\n",
    "    \n",
    "    # Append the data to the options_list\n",
    "    mb_options_list.append(mb_options_data.calls)\n",
    "    mb_options_list.append(mb_options_data.puts)\n",
    "\n",
    "# Concatenate all options data into a single DataFrame\n",
    "mb_all_options_data05192023 = pd.concat(mb_options_list)\n",
    "\n",
    "# Reset the index and drop the old one\n",
    "mb_all_options_data05192023.reset_index(drop=True, inplace=True)\n",
    "\n",
    "# Convert the expirationDate column to datetime\n",
    "mb_all_options_data05192023['expirationDate'] = pd.to_datetime(mb_all_options_data05192023['expirationDate'])\n",
    "\n",
    "# Calculate the time to expiration in days\n",
    "mb_all_options_data05192023['time_to_expiration'] = (mb_all_options_data05192023['expirationDate'] - datetime.now()).dt.days\n",
    "\n",
    "# Display the DataFrame\n",
    "print(mb_all_options_data05192023)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a343ca7a-aa0e-408d-974b-43c8584f43e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current date & time :  2023-05-21 11:06:51.071892\n",
      "~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\n",
      "File saved named:\n",
      "mb_all_options_data05192023 2023-05-21 11-06-51-071892.csv\n",
      "2023-05-21 11:06:51.071892\n",
      "~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\n"
     ]
    }
   ],
   "source": [
    "# import Lib\n",
    "import pandas as pd\n",
    "import datetime as dt\n",
    "import pytz\n",
    "import os\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# import module\n",
    "from datetime import datetime, timezone\n",
    "from datetime import date, time\n",
    "from math import trunc\n",
    "\n",
    "# get current date and time\n",
    "current_datetime = datetime.now()\n",
    "print(\"Current date & time : \", current_datetime)\n",
    "filename1 = datetime.now().strftime(\"%Y-%m-%d %H-%M-%S-%f\")\n",
    "\n",
    "# create a file object along with extension\n",
    "file_name = \"mb_all_options_data05192023 \"+filename1+\".csv\"\n",
    "#print (file_name)\n",
    "\n",
    "# converting to csv\n",
    "mb_all_options_data05192023.to_csv(file_name)\n",
    "print(\"~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\")\n",
    "print(\"File saved named:\")\n",
    "print (file_name)\n",
    "print(current_datetime)    \n",
    "print(\"~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6248b7b-aa1c-45a2-8e11-d8afc06c4c5d",
   "metadata": {},
   "source": [
    "### Getting Interest Rate Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6e2c4db0-6e52-4012-8e95-736b5bfaec8e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>US_Treasury_Rates</th>\n",
       "      <th>Yield</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1m</td>\n",
       "      <td>5.62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2m</td>\n",
       "      <td>5.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3m</td>\n",
       "      <td>5.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4m</td>\n",
       "      <td>5.46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>6m</td>\n",
       "      <td>5.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1y</td>\n",
       "      <td>5.02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2y</td>\n",
       "      <td>4.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>3y</td>\n",
       "      <td>3.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5y</td>\n",
       "      <td>3.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>7y</td>\n",
       "      <td>3.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10y</td>\n",
       "      <td>3.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>20y</td>\n",
       "      <td>4.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>30y</td>\n",
       "      <td>3.95</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   US_Treasury_Rates  Yield\n",
       "0                 1m   5.62\n",
       "1                 2m   5.27\n",
       "2                 3m   5.29\n",
       "3                 4m   5.46\n",
       "4                 6m   5.36\n",
       "5                 1y   5.02\n",
       "6                 2y   4.28\n",
       "7                 3y   3.98\n",
       "8                 5y   3.76\n",
       "9                 7y   3.74\n",
       "10               10y   3.70\n",
       "11               20y   4.07\n",
       "12               30y   3.95"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "mb_US_T_05192023 = pd.read_csv(\"US_Treasury_05192023.csv\")\n",
    "mb_US_T_05192023"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "86cf377e-7de8-4e0b-801b-3015680ef2cc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current date & time :  2023-05-21 11:06:56.696354\n",
      "~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\n",
      "File saved named:\n",
      "mb_US_T_05192023 2023-05-21 11-06-56-696354.csv\n",
      "2023-05-21 11:06:56.696354\n",
      "~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\n"
     ]
    }
   ],
   "source": [
    "# import Lib\n",
    "import pandas as pd\n",
    "import datetime as dt\n",
    "import pytz\n",
    "import os\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# import module\n",
    "from datetime import datetime, timezone\n",
    "from datetime import date, time\n",
    "from math import trunc\n",
    "\n",
    "# get current date and time\n",
    "current_datetime = datetime.now()\n",
    "print(\"Current date & time : \", current_datetime)\n",
    "filename1 = datetime.now().strftime(\"%Y-%m-%d %H-%M-%S-%f\")\n",
    "\n",
    "# create a file object along with extension\n",
    "file_name = \"mb_US_T_05192023 \"+filename1+\".csv\"\n",
    "#print (file_name)\n",
    "\n",
    "# converting to csv\n",
    "mb_US_T_05192023.to_csv(file_name)\n",
    "print(\"~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\")\n",
    "print(\"File saved named:\")\n",
    "print (file_name)\n",
    "print(current_datetime)    \n",
    "print(\"~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6ca836ed-7913-4b80-ad71-cac57a4faf6a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "b207658e-0417-4231-8bab-5edbfe19674e",
   "metadata": {},
   "source": [
    "### LOAD THE 3 CSVs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "75c9695b-3ff0-4cd8-9d65-0fa3bcc495a8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                  Open        High         Low       Close    Volume  \\\n",
      "Date                                                                   \n",
      "2018-05-21   44.916741   45.220169   44.656321   44.828342  73603200   \n",
      "2018-05-22   45.007523   45.126982   44.625251   44.716042  60962800   \n",
      "2018-05-23   44.522525   45.036199   44.381560   45.002750  80233600   \n",
      "2018-05-24   45.100712   45.117434   44.489080   44.952579  92936000   \n",
      "2018-05-25   44.971698   45.310962   44.833124   45.055321  69844000   \n",
      "...                ...         ...         ...         ...       ...   \n",
      "2023-05-15  173.160004  173.210007  171.470001  172.070007  37266700   \n",
      "2023-05-16  171.990005  173.139999  171.800003  172.070007  42110300   \n",
      "2023-05-17  171.710007  172.929993  170.419998  172.690002  57951600   \n",
      "2023-05-18  173.000000  175.240005  172.580002  175.050003  65496700   \n",
      "2023-05-19  176.389999  176.389999  174.940002  175.160004  55772400   \n",
      "\n",
      "            Dividends  Stock Splits  \n",
      "Date                                 \n",
      "2018-05-21        0.0           0.0  \n",
      "2018-05-22        0.0           0.0  \n",
      "2018-05-23        0.0           0.0  \n",
      "2018-05-24        0.0           0.0  \n",
      "2018-05-25        0.0           0.0  \n",
      "...               ...           ...  \n",
      "2023-05-15        0.0           0.0  \n",
      "2023-05-16        0.0           0.0  \n",
      "2023-05-17        0.0           0.0  \n",
      "2023-05-18        0.0           0.0  \n",
      "2023-05-19        0.0           0.0  \n",
      "\n",
      "[1259 rows x 7 columns]\n",
      "           contractSymbol              lastTradeDate  strike  lastPrice  \\\n",
      "0     AAPL230526C00095000  2023-05-19 19:36:18+00:00    95.0      80.27   \n",
      "1     AAPL230526C00100000  2023-05-17 13:59:34+00:00   100.0      75.32   \n",
      "2     AAPL230526C00110000  2023-05-16 18:17:19+00:00   110.0      62.18   \n",
      "3     AAPL230526C00115000  2023-05-08 15:00:05+00:00   115.0      58.70   \n",
      "4     AAPL230526C00120000  2023-05-17 19:25:47+00:00   120.0      52.52   \n",
      "...                   ...                        ...     ...        ...   \n",
      "1628  AAPL251219P00260000  2023-05-15 18:24:01+00:00   260.0      86.91   \n",
      "1629  AAPL251219P00270000  2023-05-05 14:01:40+00:00   270.0      96.76   \n",
      "1630  AAPL251219P00290000  2023-05-11 17:03:36+00:00   290.0     116.36   \n",
      "1631  AAPL251219P00300000  2023-04-19 13:31:50+00:00   300.0     134.00   \n",
      "1632  AAPL251219P00310000  2023-05-15 18:24:01+00:00   310.0     139.21   \n",
      "\n",
      "         bid     ask    change  percentChange  volume  openInterest  \\\n",
      "0      78.95   81.45  1.269997       1.607591     7.0             0   \n",
      "1      73.50   76.50  4.639999       6.564798     1.0             6   \n",
      "2      63.50   66.55  0.000000       0.000000    13.0            13   \n",
      "3      59.10   61.55  0.000000       0.000000     1.0             3   \n",
      "4      53.60   56.95  0.000000       0.000000     6.0             5   \n",
      "...      ...     ...       ...            ...     ...           ...   \n",
      "1628   82.75   86.65  0.000000       0.000000    86.0             0   \n",
      "1629   92.75   96.65  0.000000       0.000000     1.0             0   \n",
      "1630  112.70  116.60  0.000000       0.000000    20.0             0   \n",
      "1631    0.00    0.00  0.000000       0.000000     1.0             0   \n",
      "1632  132.70  136.60  0.000000       0.000000    93.0             0   \n",
      "\n",
      "      impliedVolatility  inTheMoney contractSize currency OptionType  \\\n",
      "0              1.812501        True      REGULAR      USD       Call   \n",
      "1              2.871097        True      REGULAR      USD       Call   \n",
      "2              2.478519        True      REGULAR      USD       Call   \n",
      "3              1.539065        True      REGULAR      USD       Call   \n",
      "4              1.332035        True      REGULAR      USD       Call   \n",
      "...                 ...         ...          ...      ...        ...   \n",
      "1628           0.168923        True      REGULAR      USD        Put   \n",
      "1629           0.180520        True      REGULAR      USD        Put   \n",
      "1630           0.200753        True      REGULAR      USD        Put   \n",
      "1631           0.000010        True      REGULAR      USD        Put   \n",
      "1632           0.220070        True      REGULAR      USD        Put   \n",
      "\n",
      "     expirationDate  time_to_expiration  \n",
      "0        2023-05-26                   4  \n",
      "1        2023-05-26                   4  \n",
      "2        2023-05-26                   4  \n",
      "3        2023-05-26                   4  \n",
      "4        2023-05-26                   4  \n",
      "...             ...                 ...  \n",
      "1628     2025-12-19                 942  \n",
      "1629     2025-12-19                 942  \n",
      "1630     2025-12-19                 942  \n",
      "1631     2025-12-19                 942  \n",
      "1632     2025-12-19                 942  \n",
      "\n",
      "[1633 rows x 17 columns]\n",
      "   US_Treasury_Rates  Yield\n",
      "0                 1m   5.62\n",
      "1                 2m   5.27\n",
      "2                 3m   5.29\n",
      "3                 4m   5.46\n",
      "4                 6m   5.36\n",
      "5                 1y   5.02\n",
      "6                 2y   4.28\n",
      "7                 3y   3.98\n",
      "8                 5y   3.76\n",
      "9                 7y   3.74\n",
      "10               10y   3.70\n",
      "11               20y   4.07\n",
      "12               30y   3.95\n"
     ]
    }
   ],
   "source": [
    "mb_src_prices = pd.read_csv(\"mb_tickerDf05192023 2023-05-21 11-06-44-380372.csv\", index_col=0)\n",
    "mb_src_options = pd.read_csv(\"mb_all_options_data05192023 2023-05-21 11-06-51-071892.csv\", index_col=0)\n",
    "mb_src_ir = pd.read_csv(\"mb_US_T_05192023 2023-05-21 11-06-56-696354.csv\", index_col=0)\n",
    "\n",
    "# Parsing the dates in the index and convert them to date only (without time or timezone info)\n",
    "mb_src_prices.index = mb_src_prices.index.map(lambda x: parse(x).date())\n",
    "\n",
    "print(mb_src_prices)\n",
    "print(mb_src_options)\n",
    "print(mb_src_ir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14eec724-57df-4b99-8fc3-fd9220106ba4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "37adb4a6-dc05-4346-a5f2-5ee49de59a6f",
   "metadata": {},
   "source": [
    "### Prices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a604f87b-5b5f-4d8a-9e4b-0fc7c60f2757",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                  AAPL\n",
      "Date                  \n",
      "2018-05-21   44.828342\n",
      "2018-05-22   44.716042\n",
      "2018-05-23   45.002750\n",
      "2018-05-24   44.952579\n",
      "2018-05-25   45.055321\n",
      "...                ...\n",
      "2023-05-15  172.070007\n",
      "2023-05-16  172.070007\n",
      "2023-05-17  172.690002\n",
      "2023-05-18  175.050003\n",
      "2023-05-19  175.160004\n",
      "\n",
      "[1259 rows x 1 columns]\n"
     ]
    }
   ],
   "source": [
    "# Copy Sources Data DataFrame\n",
    "mb_prices = mb_src_prices.copy()\n",
    "\n",
    "# Drop the unwanted columns from the DataFrame\n",
    "mb_prices = mb_prices.drop(['Open', 'High', 'Low', 'Volume', 'Dividends', 'Stock Splits'], axis=1)\n",
    "\n",
    "# Format the index to display only the date in 'yyyy-mm-dd' format\n",
    "mb_prices.index = pd.to_datetime(mb_prices.index).strftime('%Y-%m-%d')\n",
    "\n",
    "# Rename the 'Close' column to 'AAPL'\n",
    "mb_prices = mb_prices.rename(columns={'Close': 'AAPL'})\n",
    "\n",
    "# Print the updated DataFrame with formatted index\n",
    "print(mb_prices)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b9c3743-5850-4548-ad9e-40f92868e51d",
   "metadata": {},
   "source": [
    "#### mb_prices enriched"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "440fb8cf-8cf1-4f73-9730-7238988b5d74",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                  AAPL  1y Historical Volatility\n",
      "Date                                            \n",
      "2018-05-21   44.828342                       NaN\n",
      "2018-05-22   44.716042                       NaN\n",
      "2018-05-23   45.002750                       NaN\n",
      "2018-05-24   44.952579                       NaN\n",
      "2018-05-25   45.055321                       NaN\n",
      "...                ...                       ...\n",
      "2023-05-15  172.070007                  0.325388\n",
      "2023-05-16  172.070007                  0.323930\n",
      "2023-05-17  172.690002                  0.323742\n",
      "2023-05-18  175.050003                  0.323074\n",
      "2023-05-19  175.160004                  0.317648\n",
      "\n",
      "[1259 rows x 2 columns]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "# Calculating the log returns\n",
    "mb_prices['Log Returns'] = np.log(mb_prices['AAPL'] / mb_prices['AAPL'].shift(1))\n",
    "\n",
    "# Number of trading days in a year\n",
    "trading_days = 252\n",
    "\n",
    "# Calculating the 1-year rolling volatility\n",
    "mb_prices['1y Historical Volatility'] = mb_prices['Log Returns'].rolling(window=trading_days).std() * np.sqrt(trading_days)\n",
    "\n",
    "# Drop the 'Log Returns' column as we don't need it anymore\n",
    "mb_prices = mb_prices.drop(columns=['Log Returns'])\n",
    "\n",
    "print(mb_prices)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5980abdc-84b3-4bb5-a642-d64412567130",
   "metadata": {},
   "source": [
    "### Options"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "96627a0b-0e36-4d40-9fc9-92eb606705cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>contractSymbol</th>\n",
       "      <th>lastTradeDate</th>\n",
       "      <th>strike</th>\n",
       "      <th>lastPrice</th>\n",
       "      <th>impliedVolatility</th>\n",
       "      <th>inTheMoney</th>\n",
       "      <th>currency</th>\n",
       "      <th>OptionType</th>\n",
       "      <th>expirationDate</th>\n",
       "      <th>time_to_expiration</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AAPL230526C00095000</td>\n",
       "      <td>2023-05-19 19:36:18+00:00</td>\n",
       "      <td>95.0</td>\n",
       "      <td>80.27</td>\n",
       "      <td>1.812501</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AAPL230526C00100000</td>\n",
       "      <td>2023-05-17 13:59:34+00:00</td>\n",
       "      <td>100.0</td>\n",
       "      <td>75.32</td>\n",
       "      <td>2.871097</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>AAPL230526C00110000</td>\n",
       "      <td>2023-05-16 18:17:19+00:00</td>\n",
       "      <td>110.0</td>\n",
       "      <td>62.18</td>\n",
       "      <td>2.478519</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>AAPL230526C00115000</td>\n",
       "      <td>2023-05-08 15:00:05+00:00</td>\n",
       "      <td>115.0</td>\n",
       "      <td>58.70</td>\n",
       "      <td>1.539065</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>AAPL230526C00120000</td>\n",
       "      <td>2023-05-17 19:25:47+00:00</td>\n",
       "      <td>120.0</td>\n",
       "      <td>52.52</td>\n",
       "      <td>1.332035</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1628</th>\n",
       "      <td>AAPL251219P00260000</td>\n",
       "      <td>2023-05-15 18:24:01+00:00</td>\n",
       "      <td>260.0</td>\n",
       "      <td>86.91</td>\n",
       "      <td>0.168923</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-12-19</td>\n",
       "      <td>942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1629</th>\n",
       "      <td>AAPL251219P00270000</td>\n",
       "      <td>2023-05-05 14:01:40+00:00</td>\n",
       "      <td>270.0</td>\n",
       "      <td>96.76</td>\n",
       "      <td>0.180520</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-12-19</td>\n",
       "      <td>942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1630</th>\n",
       "      <td>AAPL251219P00290000</td>\n",
       "      <td>2023-05-11 17:03:36+00:00</td>\n",
       "      <td>290.0</td>\n",
       "      <td>116.36</td>\n",
       "      <td>0.200753</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-12-19</td>\n",
       "      <td>942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1631</th>\n",
       "      <td>AAPL251219P00300000</td>\n",
       "      <td>2023-04-19 13:31:50+00:00</td>\n",
       "      <td>300.0</td>\n",
       "      <td>134.00</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-12-19</td>\n",
       "      <td>942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1632</th>\n",
       "      <td>AAPL251219P00310000</td>\n",
       "      <td>2023-05-15 18:24:01+00:00</td>\n",
       "      <td>310.0</td>\n",
       "      <td>139.21</td>\n",
       "      <td>0.220070</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-12-19</td>\n",
       "      <td>942</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1633 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           contractSymbol              lastTradeDate  strike  lastPrice  \\\n",
       "0     AAPL230526C00095000  2023-05-19 19:36:18+00:00    95.0      80.27   \n",
       "1     AAPL230526C00100000  2023-05-17 13:59:34+00:00   100.0      75.32   \n",
       "2     AAPL230526C00110000  2023-05-16 18:17:19+00:00   110.0      62.18   \n",
       "3     AAPL230526C00115000  2023-05-08 15:00:05+00:00   115.0      58.70   \n",
       "4     AAPL230526C00120000  2023-05-17 19:25:47+00:00   120.0      52.52   \n",
       "...                   ...                        ...     ...        ...   \n",
       "1628  AAPL251219P00260000  2023-05-15 18:24:01+00:00   260.0      86.91   \n",
       "1629  AAPL251219P00270000  2023-05-05 14:01:40+00:00   270.0      96.76   \n",
       "1630  AAPL251219P00290000  2023-05-11 17:03:36+00:00   290.0     116.36   \n",
       "1631  AAPL251219P00300000  2023-04-19 13:31:50+00:00   300.0     134.00   \n",
       "1632  AAPL251219P00310000  2023-05-15 18:24:01+00:00   310.0     139.21   \n",
       "\n",
       "      impliedVolatility  inTheMoney currency OptionType expirationDate  \\\n",
       "0              1.812501        True      USD       Call     2023-05-26   \n",
       "1              2.871097        True      USD       Call     2023-05-26   \n",
       "2              2.478519        True      USD       Call     2023-05-26   \n",
       "3              1.539065        True      USD       Call     2023-05-26   \n",
       "4              1.332035        True      USD       Call     2023-05-26   \n",
       "...                 ...         ...      ...        ...            ...   \n",
       "1628           0.168923        True      USD        Put     2025-12-19   \n",
       "1629           0.180520        True      USD        Put     2025-12-19   \n",
       "1630           0.200753        True      USD        Put     2025-12-19   \n",
       "1631           0.000010        True      USD        Put     2025-12-19   \n",
       "1632           0.220070        True      USD        Put     2025-12-19   \n",
       "\n",
       "      time_to_expiration  \n",
       "0                      4  \n",
       "1                      4  \n",
       "2                      4  \n",
       "3                      4  \n",
       "4                      4  \n",
       "...                  ...  \n",
       "1628                 942  \n",
       "1629                 942  \n",
       "1630                 942  \n",
       "1631                 942  \n",
       "1632                 942  \n",
       "\n",
       "[1633 rows x 10 columns]"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Copy Sources Data DataFrame\n",
    "mb_options = mb_src_options.copy()\n",
    "\n",
    "# Drop the unwanted columns from the DataFrame\n",
    "mb_options = mb_options.drop(['bid', 'ask', 'change', 'percentChange', 'volume', 'openInterest', 'contractSize'], axis=1)\n",
    "\n",
    "# Print the updated DataFrame with formatted index\n",
    "mb_options"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "32abbba6-8712-4f57-a49a-79ffbc9f3750",
   "metadata": {},
   "source": [
    "### Implied Volatilities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "0c021875-25dd-40bb-b781-4a13ba3894dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Take a Copy of the Options DataFrame\n",
    "df = mb_options.copy()\n",
    "\n",
    "# Filter for call options and create a pivot table\n",
    "call_options = df[df['OptionType'] == 'Call']\n",
    "call_iv_matrix = call_options.pivot(index='time_to_expiration', columns='strike', values='impliedVolatility')\n",
    "\n",
    "# Filter for put options and create a pivot table\n",
    "put_options = df[df['OptionType'] == 'Put']\n",
    "put_iv_matrix = put_options.pivot(index='time_to_expiration', columns='strike', values='impliedVolatility')\n",
    "\n",
    "# Fill NaN values with zero (optional)\n",
    "call_iv_matrix = call_iv_matrix.fillna(0)\n",
    "put_iv_matrix = put_iv_matrix.fillna(0)\n",
    "\n",
    "# Sort the index and columns (optional)\n",
    "call_iv_matrix.sort_index(axis=0, inplace=True)\n",
    "call_iv_matrix.sort_index(axis=1, inplace=True)\n",
    "\n",
    "put_iv_matrix.sort_index(axis=0, inplace=True)\n",
    "put_iv_matrix.sort_index(axis=1, inplace=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "b32c38fe-454a-4463-9fc1-c31da245da6b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Call implied volatility matrix:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>strike</th>\n",
       "      <th>50.0</th>\n",
       "      <th>55.0</th>\n",
       "      <th>60.0</th>\n",
       "      <th>65.0</th>\n",
       "      <th>70.0</th>\n",
       "      <th>75.0</th>\n",
       "      <th>80.0</th>\n",
       "      <th>85.0</th>\n",
       "      <th>90.0</th>\n",
       "      <th>95.0</th>\n",
       "      <th>...</th>\n",
       "      <th>270.0</th>\n",
       "      <th>275.0</th>\n",
       "      <th>280.0</th>\n",
       "      <th>285.0</th>\n",
       "      <th>290.0</th>\n",
       "      <th>295.0</th>\n",
       "      <th>300.0</th>\n",
       "      <th>305.0</th>\n",
       "      <th>310.0</th>\n",
       "      <th>320.0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time_to_expiration</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.812501</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.765626</td>\n",
       "      <td>1.734376</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.884766</td>\n",
       "      <td>1.640627</td>\n",
       "      <td>1.648439</td>\n",
       "      <td>1.517581</td>\n",
       "      <td>1.426761</td>\n",
       "      <td>1.126957</td>\n",
       "      <td>1.231449</td>\n",
       "      <td>1.208988</td>\n",
       "      <td>...</td>\n",
       "      <td>0.744143</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.881837</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.562504</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.593754</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>1.410159</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>1.326175</td>\n",
       "      <td>1.328128</td>\n",
       "      <td>1.215336</td>\n",
       "      <td>1.159184</td>\n",
       "      <td>0.960450</td>\n",
       "      <td>0.987305</td>\n",
       "      <td>0.912110</td>\n",
       "      <td>0.883302</td>\n",
       "      <td>...</td>\n",
       "      <td>0.250007</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.394537</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>1.323246</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>1.229008</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>1.043950</td>\n",
       "      <td>0.983399</td>\n",
       "      <td>0.934815</td>\n",
       "      <td>0.883302</td>\n",
       "      <td>0.833254</td>\n",
       "      <td>0.784914</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.951417</td>\n",
       "      <td>0.935548</td>\n",
       "      <td>0.871827</td>\n",
       "      <td>0.835451</td>\n",
       "      <td>0.805178</td>\n",
       "      <td>0.758791</td>\n",
       "      <td>0.713870</td>\n",
       "      <td>...</td>\n",
       "      <td>0.284187</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.285163</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.382819</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.333991</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.013677</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.876222</td>\n",
       "      <td>0.832521</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.749392</td>\n",
       "      <td>0.714236</td>\n",
       "      <td>0.679447</td>\n",
       "      <td>...</td>\n",
       "      <td>0.297859</td>\n",
       "      <td>0.251961</td>\n",
       "      <td>0.292488</td>\n",
       "      <td>0.277351</td>\n",
       "      <td>0.285163</td>\n",
       "      <td>0.293952</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>1.018071</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.794558</td>\n",
       "      <td>0.755374</td>\n",
       "      <td>0.719485</td>\n",
       "      <td>0.686160</td>\n",
       "      <td>0.651371</td>\n",
       "      <td>...</td>\n",
       "      <td>0.235359</td>\n",
       "      <td>0.238289</td>\n",
       "      <td>0.246101</td>\n",
       "      <td>0.125009</td>\n",
       "      <td>0.261726</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.269539</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>207</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.827883</td>\n",
       "      <td>0.790041</td>\n",
       "      <td>0.755618</td>\n",
       "      <td>0.719729</td>\n",
       "      <td>0.686527</td>\n",
       "      <td>0.655643</td>\n",
       "      <td>0.626469</td>\n",
       "      <td>...</td>\n",
       "      <td>0.226570</td>\n",
       "      <td>0.231453</td>\n",
       "      <td>0.234383</td>\n",
       "      <td>0.236336</td>\n",
       "      <td>0.244148</td>\n",
       "      <td>0.251961</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>242</th>\n",
       "      <td>0.925294</td>\n",
       "      <td>0.881105</td>\n",
       "      <td>0.841554</td>\n",
       "      <td>0.801149</td>\n",
       "      <td>0.760378</td>\n",
       "      <td>0.729251</td>\n",
       "      <td>0.696780</td>\n",
       "      <td>0.666507</td>\n",
       "      <td>0.636478</td>\n",
       "      <td>0.608158</td>\n",
       "      <td>...</td>\n",
       "      <td>0.216316</td>\n",
       "      <td>0.213875</td>\n",
       "      <td>0.216805</td>\n",
       "      <td>0.228523</td>\n",
       "      <td>0.225594</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.239265</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.251961</td>\n",
       "      <td>0.256843</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>0.843752</td>\n",
       "      <td>0.625980</td>\n",
       "      <td>0.770754</td>\n",
       "      <td>0.741214</td>\n",
       "      <td>0.710086</td>\n",
       "      <td>0.682742</td>\n",
       "      <td>0.655521</td>\n",
       "      <td>0.623051</td>\n",
       "      <td>0.596562</td>\n",
       "      <td>0.576847</td>\n",
       "      <td>...</td>\n",
       "      <td>0.241585</td>\n",
       "      <td>0.241951</td>\n",
       "      <td>0.244148</td>\n",
       "      <td>0.254158</td>\n",
       "      <td>0.263923</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.278328</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.291023</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>0.767336</td>\n",
       "      <td>0.737918</td>\n",
       "      <td>0.708743</td>\n",
       "      <td>0.683353</td>\n",
       "      <td>0.657901</td>\n",
       "      <td>0.632572</td>\n",
       "      <td>0.608524</td>\n",
       "      <td>0.586674</td>\n",
       "      <td>0.564702</td>\n",
       "      <td>0.544255</td>\n",
       "      <td>...</td>\n",
       "      <td>0.237556</td>\n",
       "      <td>0.240486</td>\n",
       "      <td>0.225472</td>\n",
       "      <td>0.228035</td>\n",
       "      <td>0.289192</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.237312</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.250252</td>\n",
       "      <td>0.234383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>487</th>\n",
       "      <td>0.714725</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.642460</td>\n",
       "      <td>0.619144</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.577763</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.539861</td>\n",
       "      <td>0.522649</td>\n",
       "      <td>...</td>\n",
       "      <td>0.231880</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.263496</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.274055</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.230232</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.242195</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578</th>\n",
       "      <td>0.675662</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.574650</td>\n",
       "      <td>0.326911</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.522832</td>\n",
       "      <td>0.507451</td>\n",
       "      <td>...</td>\n",
       "      <td>0.250801</td>\n",
       "      <td>0.259895</td>\n",
       "      <td>0.261177</td>\n",
       "      <td>0.262153</td>\n",
       "      <td>0.263862</td>\n",
       "      <td>0.267097</td>\n",
       "      <td>0.273994</td>\n",
       "      <td>0.275825</td>\n",
       "      <td>0.278205</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>0.669803</td>\n",
       "      <td>0.648441</td>\n",
       "      <td>0.626591</td>\n",
       "      <td>0.602421</td>\n",
       "      <td>0.588688</td>\n",
       "      <td>0.570134</td>\n",
       "      <td>0.545659</td>\n",
       "      <td>0.535252</td>\n",
       "      <td>0.520055</td>\n",
       "      <td>0.504277</td>\n",
       "      <td>...</td>\n",
       "      <td>0.244057</td>\n",
       "      <td>0.241463</td>\n",
       "      <td>0.241646</td>\n",
       "      <td>0.243965</td>\n",
       "      <td>0.240364</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.234139</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.240608</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>760</th>\n",
       "      <td>0.616703</td>\n",
       "      <td>0.598637</td>\n",
       "      <td>0.581059</td>\n",
       "      <td>0.564763</td>\n",
       "      <td>0.549565</td>\n",
       "      <td>0.535222</td>\n",
       "      <td>0.520207</td>\n",
       "      <td>0.505986</td>\n",
       "      <td>0.535680</td>\n",
       "      <td>0.520635</td>\n",
       "      <td>...</td>\n",
       "      <td>0.258400</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.257820</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.268745</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.257271</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.266670</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942</th>\n",
       "      <td>0.574345</td>\n",
       "      <td>0.560551</td>\n",
       "      <td>0.545537</td>\n",
       "      <td>0.531499</td>\n",
       "      <td>0.518193</td>\n",
       "      <td>0.506169</td>\n",
       "      <td>0.538304</td>\n",
       "      <td>0.523168</td>\n",
       "      <td>0.508886</td>\n",
       "      <td>0.495305</td>\n",
       "      <td>...</td>\n",
       "      <td>0.282875</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.278114</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.267830</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.261177</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.254677</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20 rows × 67 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "strike                 50.0      55.0      60.0      65.0      70.0   \\\n",
       "time_to_expiration                                                     \n",
       "4                   0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "11                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "18                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "25                  0.000000  0.000000  1.884766  1.640627  1.648439   \n",
       "32                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "39                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "60                  1.410159  0.000010  1.326175  1.328128  1.215336   \n",
       "88                  1.323246  0.000010  1.229008  0.000010  1.043950   \n",
       "116                 0.000000  0.000000  0.000000  0.951417  0.935548   \n",
       "151                 0.000000  1.013677  0.000010  0.000010  0.876222   \n",
       "179                 1.018071  0.000010  0.000000  0.000000  0.000000   \n",
       "207                 0.000000  0.000000  0.000000  0.827883  0.790041   \n",
       "242                 0.925294  0.881105  0.841554  0.801149  0.760378   \n",
       "298                 0.843752  0.625980  0.770754  0.741214  0.710086   \n",
       "396                 0.767336  0.737918  0.708743  0.683353  0.657901   \n",
       "487                 0.714725  0.000000  0.000000  0.642460  0.619144   \n",
       "578                 0.675662  0.000010  0.000010  0.000000  0.000000   \n",
       "606                 0.669803  0.648441  0.626591  0.602421  0.588688   \n",
       "760                 0.616703  0.598637  0.581059  0.564763  0.549565   \n",
       "942                 0.574345  0.560551  0.545537  0.531499  0.518193   \n",
       "\n",
       "strike                 75.0      80.0      85.0      90.0      95.0   ...  \\\n",
       "time_to_expiration                                                    ...   \n",
       "4                   0.000000  0.000000  0.000000  0.000000  1.812501  ...   \n",
       "11                  0.000000  0.000000  1.765626  1.734376  0.000000  ...   \n",
       "18                  0.000000  0.000000  0.000000  0.000000  0.000000  ...   \n",
       "25                  1.517581  1.426761  1.126957  1.231449  1.208988  ...   \n",
       "32                  0.000000  0.000000  0.000000  0.000000  0.000000  ...   \n",
       "39                  0.000000  0.000000  0.000000  0.000000  0.000000  ...   \n",
       "60                  1.159184  0.960450  0.987305  0.912110  0.883302  ...   \n",
       "88                  0.983399  0.934815  0.883302  0.833254  0.784914  ...   \n",
       "116                 0.871827  0.835451  0.805178  0.758791  0.713870  ...   \n",
       "151                 0.832521  0.000010  0.749392  0.714236  0.679447  ...   \n",
       "179                 0.794558  0.755374  0.719485  0.686160  0.651371  ...   \n",
       "207                 0.755618  0.719729  0.686527  0.655643  0.626469  ...   \n",
       "242                 0.729251  0.696780  0.666507  0.636478  0.608158  ...   \n",
       "298                 0.682742  0.655521  0.623051  0.596562  0.576847  ...   \n",
       "396                 0.632572  0.608524  0.586674  0.564702  0.544255  ...   \n",
       "487                 0.000000  0.577763  0.000010  0.539861  0.522649  ...   \n",
       "578                 0.574650  0.326911  0.000000  0.522832  0.507451  ...   \n",
       "606                 0.570134  0.545659  0.535252  0.520055  0.504277  ...   \n",
       "760                 0.535222  0.520207  0.505986  0.535680  0.520635  ...   \n",
       "942                 0.506169  0.538304  0.523168  0.508886  0.495305  ...   \n",
       "\n",
       "strike                 270.0     275.0     280.0     285.0     290.0  \\\n",
       "time_to_expiration                                                     \n",
       "4                   0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "11                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "18                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "25                  0.744143  0.000000  0.881837  0.000000  0.562504   \n",
       "32                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "39                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "60                  0.250007  0.000000  0.394537  0.000000  0.000000   \n",
       "88                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "116                 0.284187  0.000000  0.285163  0.000000  0.382819   \n",
       "151                 0.297859  0.251961  0.292488  0.277351  0.285163   \n",
       "179                 0.235359  0.238289  0.246101  0.125009  0.261726   \n",
       "207                 0.226570  0.231453  0.234383  0.236336  0.244148   \n",
       "242                 0.216316  0.213875  0.216805  0.228523  0.225594   \n",
       "298                 0.241585  0.241951  0.244148  0.254158  0.263923   \n",
       "396                 0.237556  0.240486  0.225472  0.228035  0.289192   \n",
       "487                 0.231880  0.000000  0.263496  0.000000  0.274055   \n",
       "578                 0.250801  0.259895  0.261177  0.262153  0.263862   \n",
       "606                 0.244057  0.241463  0.241646  0.243965  0.240364   \n",
       "760                 0.258400  0.000000  0.257820  0.000000  0.268745   \n",
       "942                 0.282875  0.000000  0.278114  0.000000  0.267830   \n",
       "\n",
       "strike                 295.0     300.0     305.0     310.0     320.0  \n",
       "time_to_expiration                                                    \n",
       "4                   0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "11                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "18                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "25                  0.000000  0.593754  0.000000  0.000000  0.000000  \n",
       "32                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "39                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "60                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "88                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "116                 0.000000  0.333991  0.000000  0.000000  0.000000  \n",
       "151                 0.293952  0.000000  0.000000  0.000000  0.000000  \n",
       "179                 0.000000  0.269539  0.000000  0.000000  0.000000  \n",
       "207                 0.251961  0.000000  0.000000  0.000000  0.000000  \n",
       "242                 0.000000  0.239265  0.000000  0.251961  0.256843  \n",
       "298                 0.000000  0.278328  0.000000  0.291023  0.000000  \n",
       "396                 0.000000  0.237312  0.000000  0.250252  0.234383  \n",
       "487                 0.000000  0.230232  0.000000  0.242195  0.000000  \n",
       "578                 0.267097  0.273994  0.275825  0.278205  0.000000  \n",
       "606                 0.000000  0.234139  0.000000  0.240608  0.000000  \n",
       "760                 0.000000  0.257271  0.000000  0.266670  0.000000  \n",
       "942                 0.000000  0.261177  0.000000  0.254677  0.000000  \n",
       "\n",
       "[20 rows x 67 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"Call implied volatility matrix:\")\n",
    "call_iv_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7945f368-e096-4346-a139-cfa25daee075",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Put implied volatility matrix:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>strike</th>\n",
       "      <th>50.0</th>\n",
       "      <th>55.0</th>\n",
       "      <th>60.0</th>\n",
       "      <th>65.0</th>\n",
       "      <th>70.0</th>\n",
       "      <th>75.0</th>\n",
       "      <th>80.0</th>\n",
       "      <th>85.0</th>\n",
       "      <th>90.0</th>\n",
       "      <th>95.0</th>\n",
       "      <th>...</th>\n",
       "      <th>260.0</th>\n",
       "      <th>265.0</th>\n",
       "      <th>270.0</th>\n",
       "      <th>275.0</th>\n",
       "      <th>280.0</th>\n",
       "      <th>285.0</th>\n",
       "      <th>290.0</th>\n",
       "      <th>300.0</th>\n",
       "      <th>310.0</th>\n",
       "      <th>320.0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time_to_expiration</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.000002</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.187505</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.625002</td>\n",
       "      <td>1.500002</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2.617191</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.500002</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.273441</td>\n",
       "      <td>1.332035</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.164067</td>\n",
       "      <td>1.136723</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.218754</td>\n",
       "      <td>1.125004</td>\n",
       "      <td>1.031255</td>\n",
       "      <td>1.109379</td>\n",
       "      <td>0.953125</td>\n",
       "      <td>1.080083</td>\n",
       "      <td>1.000005</td>\n",
       "      <td>0.703128</td>\n",
       "      <td>...</td>\n",
       "      <td>2.614872</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.050478</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.795169</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.623658</td>\n",
       "      <td>2.371342</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>1.843751</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.818361</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>1.199223</td>\n",
       "      <td>0.859376</td>\n",
       "      <td>0.929688</td>\n",
       "      <td>0.957032</td>\n",
       "      <td>0.726565</td>\n",
       "      <td>0.837892</td>\n",
       "      <td>0.679691</td>\n",
       "      <td>0.617191</td>\n",
       "      <td>0.570317</td>\n",
       "      <td>0.546880</td>\n",
       "      <td>...</td>\n",
       "      <td>0.636967</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.404605</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.032964</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>0.781252</td>\n",
       "      <td>0.718753</td>\n",
       "      <td>0.726565</td>\n",
       "      <td>0.810549</td>\n",
       "      <td>0.753909</td>\n",
       "      <td>0.609379</td>\n",
       "      <td>0.574223</td>\n",
       "      <td>0.531255</td>\n",
       "      <td>0.500005</td>\n",
       "      <td>0.513677</td>\n",
       "      <td>...</td>\n",
       "      <td>1.237431</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.617191</td>\n",
       "      <td>0.582035</td>\n",
       "      <td>0.539067</td>\n",
       "      <td>0.539067</td>\n",
       "      <td>0.519536</td>\n",
       "      <td>0.502935</td>\n",
       "      <td>0.479497</td>\n",
       "      <td>...</td>\n",
       "      <td>1.221989</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.107365</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.500979</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.540926</td>\n",
       "      <td>0.598149</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.617191</td>\n",
       "      <td>0.582035</td>\n",
       "      <td>0.531255</td>\n",
       "      <td>0.548833</td>\n",
       "      <td>0.522466</td>\n",
       "      <td>0.507817</td>\n",
       "      <td>0.486333</td>\n",
       "      <td>0.469732</td>\n",
       "      <td>0.449713</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.396121</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>0.652347</td>\n",
       "      <td>0.595707</td>\n",
       "      <td>0.566411</td>\n",
       "      <td>0.513677</td>\n",
       "      <td>0.503911</td>\n",
       "      <td>0.507817</td>\n",
       "      <td>0.497564</td>\n",
       "      <td>0.475103</td>\n",
       "      <td>0.456548</td>\n",
       "      <td>0.437994</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>207</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.525395</td>\n",
       "      <td>0.508794</td>\n",
       "      <td>0.494146</td>\n",
       "      <td>0.476079</td>\n",
       "      <td>0.458013</td>\n",
       "      <td>0.443853</td>\n",
       "      <td>0.426275</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.383551</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.406744</td>\n",
       "      <td>1.057530</td>\n",
       "      <td>1.071507</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>242</th>\n",
       "      <td>0.580082</td>\n",
       "      <td>0.555669</td>\n",
       "      <td>0.536137</td>\n",
       "      <td>0.508794</td>\n",
       "      <td>0.496099</td>\n",
       "      <td>0.479497</td>\n",
       "      <td>0.458502</td>\n",
       "      <td>0.442388</td>\n",
       "      <td>0.425543</td>\n",
       "      <td>0.409674</td>\n",
       "      <td>...</td>\n",
       "      <td>0.332404</td>\n",
       "      <td>0.532018</td>\n",
       "      <td>0.882112</td>\n",
       "      <td>0.867158</td>\n",
       "      <td>0.702273</td>\n",
       "      <td>0.977905</td>\n",
       "      <td>0.650516</td>\n",
       "      <td>0.416388</td>\n",
       "      <td>0.437384</td>\n",
       "      <td>0.455084</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>0.568364</td>\n",
       "      <td>0.564457</td>\n",
       "      <td>0.522466</td>\n",
       "      <td>0.506841</td>\n",
       "      <td>0.524907</td>\n",
       "      <td>0.499028</td>\n",
       "      <td>0.477544</td>\n",
       "      <td>0.457647</td>\n",
       "      <td>0.439825</td>\n",
       "      <td>0.422491</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.854829</td>\n",
       "      <td>0.997162</td>\n",
       "      <td>0.339789</td>\n",
       "      <td>0.749331</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>0.563481</td>\n",
       "      <td>0.596195</td>\n",
       "      <td>0.502935</td>\n",
       "      <td>0.460455</td>\n",
       "      <td>0.455572</td>\n",
       "      <td>0.430914</td>\n",
       "      <td>0.497197</td>\n",
       "      <td>0.399176</td>\n",
       "      <td>0.386481</td>\n",
       "      <td>0.432257</td>\n",
       "      <td>...</td>\n",
       "      <td>0.745913</td>\n",
       "      <td>0.269661</td>\n",
       "      <td>0.280098</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.788119</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.736056</td>\n",
       "      <td>0.491399</td>\n",
       "      <td>0.931672</td>\n",
       "      <td>0.411322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>487</th>\n",
       "      <td>0.515142</td>\n",
       "      <td>0.537846</td>\n",
       "      <td>0.516362</td>\n",
       "      <td>0.520757</td>\n",
       "      <td>0.425665</td>\n",
       "      <td>0.402594</td>\n",
       "      <td>0.396002</td>\n",
       "      <td>0.382575</td>\n",
       "      <td>0.424933</td>\n",
       "      <td>0.407416</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.302192</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.612583</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578</th>\n",
       "      <td>0.536626</td>\n",
       "      <td>0.505376</td>\n",
       "      <td>0.542729</td>\n",
       "      <td>0.512700</td>\n",
       "      <td>0.488653</td>\n",
       "      <td>0.466558</td>\n",
       "      <td>0.442571</td>\n",
       "      <td>0.423834</td>\n",
       "      <td>0.406744</td>\n",
       "      <td>0.392523</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.373419</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>0.511968</td>\n",
       "      <td>0.563725</td>\n",
       "      <td>0.466924</td>\n",
       "      <td>0.474981</td>\n",
       "      <td>0.449346</td>\n",
       "      <td>0.421515</td>\n",
       "      <td>0.396368</td>\n",
       "      <td>0.378668</td>\n",
       "      <td>0.370001</td>\n",
       "      <td>0.355841</td>\n",
       "      <td>...</td>\n",
       "      <td>0.248176</td>\n",
       "      <td>0.682224</td>\n",
       "      <td>0.611363</td>\n",
       "      <td>0.276435</td>\n",
       "      <td>0.540166</td>\n",
       "      <td>0.808992</td>\n",
       "      <td>0.252327</td>\n",
       "      <td>0.450628</td>\n",
       "      <td>0.762331</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>760</th>\n",
       "      <td>0.500127</td>\n",
       "      <td>0.522832</td>\n",
       "      <td>0.440801</td>\n",
       "      <td>0.458135</td>\n",
       "      <td>0.444952</td>\n",
       "      <td>0.386725</td>\n",
       "      <td>0.406012</td>\n",
       "      <td>0.393195</td>\n",
       "      <td>0.340094</td>\n",
       "      <td>0.346900</td>\n",
       "      <td>...</td>\n",
       "      <td>0.187752</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.560780</td>\n",
       "      <td>0.245918</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942</th>\n",
       "      <td>0.426886</td>\n",
       "      <td>0.477422</td>\n",
       "      <td>0.453497</td>\n",
       "      <td>0.374884</td>\n",
       "      <td>0.414068</td>\n",
       "      <td>0.395148</td>\n",
       "      <td>0.382880</td>\n",
       "      <td>0.367804</td>\n",
       "      <td>0.331306</td>\n",
       "      <td>0.326942</td>\n",
       "      <td>...</td>\n",
       "      <td>0.168923</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.180520</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.200753</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.220070</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20 rows × 65 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "strike                 50.0      55.0      60.0      65.0      70.0   \\\n",
       "time_to_expiration                                                     \n",
       "4                   3.000002  0.000000  0.000000  0.000000  2.187505   \n",
       "11                  2.617191  0.000000  0.000000  0.000000  1.500002   \n",
       "18                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "25                  0.000000  0.000000  1.218754  1.125004  1.031255   \n",
       "32                  1.843751  0.000000  0.000000  0.000000  0.000000   \n",
       "39                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "60                  1.199223  0.859376  0.929688  0.957032  0.726565   \n",
       "88                  0.781252  0.718753  0.726565  0.810549  0.753909   \n",
       "116                 0.000000  0.000000  0.000000  0.617191  0.582035   \n",
       "151                 0.000000  0.617191  0.582035  0.531255  0.548833   \n",
       "179                 0.652347  0.595707  0.566411  0.513677  0.503911   \n",
       "207                 0.000000  0.000000  0.000000  0.525395  0.508794   \n",
       "242                 0.580082  0.555669  0.536137  0.508794  0.496099   \n",
       "298                 0.568364  0.564457  0.522466  0.506841  0.524907   \n",
       "396                 0.563481  0.596195  0.502935  0.460455  0.455572   \n",
       "487                 0.515142  0.537846  0.516362  0.520757  0.425665   \n",
       "578                 0.536626  0.505376  0.542729  0.512700  0.488653   \n",
       "606                 0.511968  0.563725  0.466924  0.474981  0.449346   \n",
       "760                 0.500127  0.522832  0.440801  0.458135  0.444952   \n",
       "942                 0.426886  0.477422  0.453497  0.374884  0.414068   \n",
       "\n",
       "strike                 75.0      80.0      85.0      90.0      95.0   ...  \\\n",
       "time_to_expiration                                                    ...   \n",
       "4                   0.000000  0.000000  0.000000  1.625002  1.500002  ...   \n",
       "11                  0.000000  0.000000  0.000000  1.273441  1.332035  ...   \n",
       "18                  0.000000  0.000000  0.000000  1.164067  1.136723  ...   \n",
       "25                  1.109379  0.953125  1.080083  1.000005  0.703128  ...   \n",
       "32                  0.000000  0.000000  0.000000  0.000000  0.000000  ...   \n",
       "39                  0.000000  0.000000  0.000000  0.818361  0.000000  ...   \n",
       "60                  0.837892  0.679691  0.617191  0.570317  0.546880  ...   \n",
       "88                  0.609379  0.574223  0.531255  0.500005  0.513677  ...   \n",
       "116                 0.539067  0.539067  0.519536  0.502935  0.479497  ...   \n",
       "151                 0.522466  0.507817  0.486333  0.469732  0.449713  ...   \n",
       "179                 0.507817  0.497564  0.475103  0.456548  0.437994  ...   \n",
       "207                 0.494146  0.476079  0.458013  0.443853  0.426275  ...   \n",
       "242                 0.479497  0.458502  0.442388  0.425543  0.409674  ...   \n",
       "298                 0.499028  0.477544  0.457647  0.439825  0.422491  ...   \n",
       "396                 0.430914  0.497197  0.399176  0.386481  0.432257  ...   \n",
       "487                 0.402594  0.396002  0.382575  0.424933  0.407416  ...   \n",
       "578                 0.466558  0.442571  0.423834  0.406744  0.392523  ...   \n",
       "606                 0.421515  0.396368  0.378668  0.370001  0.355841  ...   \n",
       "760                 0.386725  0.406012  0.393195  0.340094  0.346900  ...   \n",
       "942                 0.395148  0.382880  0.367804  0.331306  0.326942  ...   \n",
       "\n",
       "strike                 260.0     265.0     270.0     275.0     280.0  \\\n",
       "time_to_expiration                                                     \n",
       "4                   0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "11                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "18                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "25                  2.614872  0.000000  3.050478  0.000000  2.795169   \n",
       "32                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "39                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "60                  0.636967  0.000000  1.404605  0.000000  2.032964   \n",
       "88                  1.237431  0.000000  0.000000  0.000000  0.000000   \n",
       "116                 1.221989  0.000000  1.107365  0.000000  1.500979   \n",
       "151                 0.000000  0.000000  0.000000  1.396121  0.000000   \n",
       "179                 0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "207                 0.000000  0.000000  0.383551  0.000000  0.406744   \n",
       "242                 0.332404  0.532018  0.882112  0.867158  0.702273   \n",
       "298                 0.000000  0.000000  0.854829  0.997162  0.339789   \n",
       "396                 0.745913  0.269661  0.280098  0.000000  0.788119   \n",
       "487                 0.000000  0.000000  0.000000  0.000000  0.302192   \n",
       "578                 0.000000  0.373419  0.000000  0.000000  0.000000   \n",
       "606                 0.248176  0.682224  0.611363  0.276435  0.540166   \n",
       "760                 0.187752  0.000000  0.000000  0.000000  0.000000   \n",
       "942                 0.168923  0.000000  0.180520  0.000000  0.000000   \n",
       "\n",
       "strike                 285.0     290.0     300.0     310.0     320.0  \n",
       "time_to_expiration                                                    \n",
       "4                   0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "11                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "18                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "25                  0.000000  3.623658  2.371342  0.000000  0.000000  \n",
       "32                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "39                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "60                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "88                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "116                 0.000000  1.540926  0.598149  0.000000  0.000000  \n",
       "151                 0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "179                 0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "207                 1.057530  1.071507  0.000000  0.000000  0.000000  \n",
       "242                 0.977905  0.650516  0.416388  0.437384  0.455084  \n",
       "298                 0.749331  0.000000  0.000000  0.000000  0.000000  \n",
       "396                 0.000000  0.736056  0.491399  0.931672  0.411322  \n",
       "487                 0.000000  0.000000  0.612583  0.000000  0.000000  \n",
       "578                 0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "606                 0.808992  0.252327  0.450628  0.762331  0.000000  \n",
       "760                 0.000000  0.000000  0.560780  0.245918  0.000000  \n",
       "942                 0.000000  0.200753  0.000010  0.220070  0.000000  \n",
       "\n",
       "[20 rows x 65 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"\\nPut implied volatility matrix:\")\n",
    "put_iv_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b4cb28a0-b439-4633-86b6-6dfd853fa335",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Selected columns from Call implied volatility matrix:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>strike</th>\n",
       "      <th>50.0</th>\n",
       "      <th>55.0</th>\n",
       "      <th>60.0</th>\n",
       "      <th>65.0</th>\n",
       "      <th>70.0</th>\n",
       "      <th>295.0</th>\n",
       "      <th>300.0</th>\n",
       "      <th>305.0</th>\n",
       "      <th>310.0</th>\n",
       "      <th>320.0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time_to_expiration</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.884766</td>\n",
       "      <td>1.640627</td>\n",
       "      <td>1.648439</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.593754</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>1.410159</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>1.326175</td>\n",
       "      <td>1.328128</td>\n",
       "      <td>1.215336</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>1.323246</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>1.229008</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>1.043950</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.951417</td>\n",
       "      <td>0.935548</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.333991</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.013677</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.876222</td>\n",
       "      <td>0.293952</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>1.018071</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.269539</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>207</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.827883</td>\n",
       "      <td>0.790041</td>\n",
       "      <td>0.251961</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>242</th>\n",
       "      <td>0.925294</td>\n",
       "      <td>0.881105</td>\n",
       "      <td>0.841554</td>\n",
       "      <td>0.801149</td>\n",
       "      <td>0.760378</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.239265</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.251961</td>\n",
       "      <td>0.256843</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>0.843752</td>\n",
       "      <td>0.625980</td>\n",
       "      <td>0.770754</td>\n",
       "      <td>0.741214</td>\n",
       "      <td>0.710086</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.278328</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.291023</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>0.767336</td>\n",
       "      <td>0.737918</td>\n",
       "      <td>0.708743</td>\n",
       "      <td>0.683353</td>\n",
       "      <td>0.657901</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.237312</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.250252</td>\n",
       "      <td>0.234383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>487</th>\n",
       "      <td>0.714725</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.642460</td>\n",
       "      <td>0.619144</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.230232</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.242195</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578</th>\n",
       "      <td>0.675662</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.267097</td>\n",
       "      <td>0.273994</td>\n",
       "      <td>0.275825</td>\n",
       "      <td>0.278205</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>0.669803</td>\n",
       "      <td>0.648441</td>\n",
       "      <td>0.626591</td>\n",
       "      <td>0.602421</td>\n",
       "      <td>0.588688</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.234139</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.240608</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>760</th>\n",
       "      <td>0.616703</td>\n",
       "      <td>0.598637</td>\n",
       "      <td>0.581059</td>\n",
       "      <td>0.564763</td>\n",
       "      <td>0.549565</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.257271</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.266670</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942</th>\n",
       "      <td>0.574345</td>\n",
       "      <td>0.560551</td>\n",
       "      <td>0.545537</td>\n",
       "      <td>0.531499</td>\n",
       "      <td>0.518193</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.261177</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.254677</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "strike                 50.0      55.0      60.0      65.0      70.0   \\\n",
       "time_to_expiration                                                     \n",
       "4                   0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "11                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "18                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "25                  0.000000  0.000000  1.884766  1.640627  1.648439   \n",
       "32                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "39                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "60                  1.410159  0.000010  1.326175  1.328128  1.215336   \n",
       "88                  1.323246  0.000010  1.229008  0.000010  1.043950   \n",
       "116                 0.000000  0.000000  0.000000  0.951417  0.935548   \n",
       "151                 0.000000  1.013677  0.000010  0.000010  0.876222   \n",
       "179                 1.018071  0.000010  0.000000  0.000000  0.000000   \n",
       "207                 0.000000  0.000000  0.000000  0.827883  0.790041   \n",
       "242                 0.925294  0.881105  0.841554  0.801149  0.760378   \n",
       "298                 0.843752  0.625980  0.770754  0.741214  0.710086   \n",
       "396                 0.767336  0.737918  0.708743  0.683353  0.657901   \n",
       "487                 0.714725  0.000000  0.000000  0.642460  0.619144   \n",
       "578                 0.675662  0.000010  0.000010  0.000000  0.000000   \n",
       "606                 0.669803  0.648441  0.626591  0.602421  0.588688   \n",
       "760                 0.616703  0.598637  0.581059  0.564763  0.549565   \n",
       "942                 0.574345  0.560551  0.545537  0.531499  0.518193   \n",
       "\n",
       "strike                 295.0     300.0     305.0     310.0     320.0  \n",
       "time_to_expiration                                                    \n",
       "4                   0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "11                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "18                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "25                  0.000000  0.593754  0.000000  0.000000  0.000000  \n",
       "32                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "39                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "60                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "88                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "116                 0.000000  0.333991  0.000000  0.000000  0.000000  \n",
       "151                 0.293952  0.000000  0.000000  0.000000  0.000000  \n",
       "179                 0.000000  0.269539  0.000000  0.000000  0.000000  \n",
       "207                 0.251961  0.000000  0.000000  0.000000  0.000000  \n",
       "242                 0.000000  0.239265  0.000000  0.251961  0.256843  \n",
       "298                 0.000000  0.278328  0.000000  0.291023  0.000000  \n",
       "396                 0.000000  0.237312  0.000000  0.250252  0.234383  \n",
       "487                 0.000000  0.230232  0.000000  0.242195  0.000000  \n",
       "578                 0.267097  0.273994  0.275825  0.278205  0.000000  \n",
       "606                 0.000000  0.234139  0.000000  0.240608  0.000000  \n",
       "760                 0.000000  0.257271  0.000000  0.266670  0.000000  \n",
       "942                 0.000000  0.261177  0.000000  0.254677  0.000000  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Select first 5 and last 5 columns of Call implied volatility matrix\n",
    "call_selected = pd.concat([call_iv_matrix.iloc[:, :5], call_iv_matrix.iloc[:, -5:]], axis=1)\n",
    "print(\"Selected columns from Call implied volatility matrix:\")\n",
    "call_selected"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "e22b366c-fe3f-4dcd-8611-0f6d4b1b3261",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Selected columns from Put implied volatility matrix:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>strike</th>\n",
       "      <th>50.0</th>\n",
       "      <th>55.0</th>\n",
       "      <th>60.0</th>\n",
       "      <th>65.0</th>\n",
       "      <th>70.0</th>\n",
       "      <th>285.0</th>\n",
       "      <th>290.0</th>\n",
       "      <th>300.0</th>\n",
       "      <th>310.0</th>\n",
       "      <th>320.0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time_to_expiration</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.000002</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.187505</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2.617191</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.500002</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.218754</td>\n",
       "      <td>1.125004</td>\n",
       "      <td>1.031255</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.623658</td>\n",
       "      <td>2.371342</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>1.843751</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>1.199223</td>\n",
       "      <td>0.859376</td>\n",
       "      <td>0.929688</td>\n",
       "      <td>0.957032</td>\n",
       "      <td>0.726565</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>0.781252</td>\n",
       "      <td>0.718753</td>\n",
       "      <td>0.726565</td>\n",
       "      <td>0.810549</td>\n",
       "      <td>0.753909</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.617191</td>\n",
       "      <td>0.582035</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.540926</td>\n",
       "      <td>0.598149</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.617191</td>\n",
       "      <td>0.582035</td>\n",
       "      <td>0.531255</td>\n",
       "      <td>0.548833</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>0.652347</td>\n",
       "      <td>0.595707</td>\n",
       "      <td>0.566411</td>\n",
       "      <td>0.513677</td>\n",
       "      <td>0.503911</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>207</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.525395</td>\n",
       "      <td>0.508794</td>\n",
       "      <td>1.057530</td>\n",
       "      <td>1.071507</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>242</th>\n",
       "      <td>0.580082</td>\n",
       "      <td>0.555669</td>\n",
       "      <td>0.536137</td>\n",
       "      <td>0.508794</td>\n",
       "      <td>0.496099</td>\n",
       "      <td>0.977905</td>\n",
       "      <td>0.650516</td>\n",
       "      <td>0.416388</td>\n",
       "      <td>0.437384</td>\n",
       "      <td>0.455084</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>0.568364</td>\n",
       "      <td>0.564457</td>\n",
       "      <td>0.522466</td>\n",
       "      <td>0.506841</td>\n",
       "      <td>0.524907</td>\n",
       "      <td>0.749331</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>0.563481</td>\n",
       "      <td>0.596195</td>\n",
       "      <td>0.502935</td>\n",
       "      <td>0.460455</td>\n",
       "      <td>0.455572</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.736056</td>\n",
       "      <td>0.491399</td>\n",
       "      <td>0.931672</td>\n",
       "      <td>0.411322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>487</th>\n",
       "      <td>0.515142</td>\n",
       "      <td>0.537846</td>\n",
       "      <td>0.516362</td>\n",
       "      <td>0.520757</td>\n",
       "      <td>0.425665</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.612583</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578</th>\n",
       "      <td>0.536626</td>\n",
       "      <td>0.505376</td>\n",
       "      <td>0.542729</td>\n",
       "      <td>0.512700</td>\n",
       "      <td>0.488653</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>0.511968</td>\n",
       "      <td>0.563725</td>\n",
       "      <td>0.466924</td>\n",
       "      <td>0.474981</td>\n",
       "      <td>0.449346</td>\n",
       "      <td>0.808992</td>\n",
       "      <td>0.252327</td>\n",
       "      <td>0.450628</td>\n",
       "      <td>0.762331</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>760</th>\n",
       "      <td>0.500127</td>\n",
       "      <td>0.522832</td>\n",
       "      <td>0.440801</td>\n",
       "      <td>0.458135</td>\n",
       "      <td>0.444952</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.560780</td>\n",
       "      <td>0.245918</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942</th>\n",
       "      <td>0.426886</td>\n",
       "      <td>0.477422</td>\n",
       "      <td>0.453497</td>\n",
       "      <td>0.374884</td>\n",
       "      <td>0.414068</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.200753</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>0.220070</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "strike                 50.0      55.0      60.0      65.0      70.0   \\\n",
       "time_to_expiration                                                     \n",
       "4                   3.000002  0.000000  0.000000  0.000000  2.187505   \n",
       "11                  2.617191  0.000000  0.000000  0.000000  1.500002   \n",
       "18                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "25                  0.000000  0.000000  1.218754  1.125004  1.031255   \n",
       "32                  1.843751  0.000000  0.000000  0.000000  0.000000   \n",
       "39                  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "60                  1.199223  0.859376  0.929688  0.957032  0.726565   \n",
       "88                  0.781252  0.718753  0.726565  0.810549  0.753909   \n",
       "116                 0.000000  0.000000  0.000000  0.617191  0.582035   \n",
       "151                 0.000000  0.617191  0.582035  0.531255  0.548833   \n",
       "179                 0.652347  0.595707  0.566411  0.513677  0.503911   \n",
       "207                 0.000000  0.000000  0.000000  0.525395  0.508794   \n",
       "242                 0.580082  0.555669  0.536137  0.508794  0.496099   \n",
       "298                 0.568364  0.564457  0.522466  0.506841  0.524907   \n",
       "396                 0.563481  0.596195  0.502935  0.460455  0.455572   \n",
       "487                 0.515142  0.537846  0.516362  0.520757  0.425665   \n",
       "578                 0.536626  0.505376  0.542729  0.512700  0.488653   \n",
       "606                 0.511968  0.563725  0.466924  0.474981  0.449346   \n",
       "760                 0.500127  0.522832  0.440801  0.458135  0.444952   \n",
       "942                 0.426886  0.477422  0.453497  0.374884  0.414068   \n",
       "\n",
       "strike                 285.0     290.0     300.0     310.0     320.0  \n",
       "time_to_expiration                                                    \n",
       "4                   0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "11                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "18                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "25                  0.000000  3.623658  2.371342  0.000000  0.000000  \n",
       "32                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "39                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "60                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "88                  0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "116                 0.000000  1.540926  0.598149  0.000000  0.000000  \n",
       "151                 0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "179                 0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "207                 1.057530  1.071507  0.000000  0.000000  0.000000  \n",
       "242                 0.977905  0.650516  0.416388  0.437384  0.455084  \n",
       "298                 0.749331  0.000000  0.000000  0.000000  0.000000  \n",
       "396                 0.000000  0.736056  0.491399  0.931672  0.411322  \n",
       "487                 0.000000  0.000000  0.612583  0.000000  0.000000  \n",
       "578                 0.000000  0.000000  0.000000  0.000000  0.000000  \n",
       "606                 0.808992  0.252327  0.450628  0.762331  0.000000  \n",
       "760                 0.000000  0.000000  0.560780  0.245918  0.000000  \n",
       "942                 0.000000  0.200753  0.000010  0.220070  0.000000  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Select first 5 and last 5 columns of Put implied volatility matrix\n",
    "put_selected = pd.concat([put_iv_matrix.iloc[:, :5], put_iv_matrix.iloc[:, -5:]], axis=1)\n",
    "print(\"\\nSelected columns from Put implied volatility matrix:\")\n",
    "put_selected"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1eb81514-dcef-43da-b73f-150f8f06aec9",
   "metadata": {},
   "source": [
    "#### mb_iv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "0af08967-e7f7-4512-8595-ced3b7b6bfb0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Combined implied volatility matrix:\n",
      "strike                 50.0      55.0      60.0      65.0      70.0   \\\n",
      "time_to_expiration                                                     \n",
      "4                   3.000002       NaN       NaN       NaN  2.187505   \n",
      "11                  2.617191       NaN       NaN       NaN  1.500002   \n",
      "18                       NaN       NaN       NaN       NaN       NaN   \n",
      "25                       NaN       NaN  1.551760  1.382816  1.339847   \n",
      "32                  1.843751       NaN       NaN       NaN       NaN   \n",
      "39                       NaN       NaN       NaN       NaN       NaN   \n",
      "60                  1.304691  0.429693  1.127932  1.142580  0.970951   \n",
      "88                  1.052249  0.359381  0.977786  0.405279  0.898929   \n",
      "116                      NaN       NaN       NaN  0.784304  0.758791   \n",
      "151                      NaN  0.815434  0.291023  0.265632  0.712527   \n",
      "179                 0.835209  0.297859  0.566411  0.513677  0.503911   \n",
      "207                      NaN       NaN       NaN  0.676639  0.649418   \n",
      "242                 0.752688  0.718387  0.688846  0.654972  0.628239   \n",
      "298                 0.706058  0.595219  0.646610  0.624027  0.617497   \n",
      "396                 0.665409  0.667057  0.605839  0.571904  0.556737   \n",
      "487                 0.614933  0.537846  0.516362  0.581608  0.522405   \n",
      "578                 0.606144  0.252693  0.271370  0.512700  0.488653   \n",
      "606                 0.590885  0.606083  0.546757  0.538701  0.519017   \n",
      "760                 0.558415  0.560734  0.510930  0.511449  0.497258   \n",
      "942                 0.500615  0.518987  0.499517  0.453192  0.466131   \n",
      "\n",
      "strike                 75.0      80.0      85.0      90.0      95.0   ...  \\\n",
      "time_to_expiration                                                    ...   \n",
      "4                        NaN       NaN       NaN  1.625002  1.656252  ...   \n",
      "11                       NaN       NaN  1.765626  1.503909  1.332035  ...   \n",
      "18                       NaN       NaN       NaN  1.164067  1.136723  ...   \n",
      "25                  1.313480  1.189943  1.103520  1.115727  0.956058  ...   \n",
      "32                       NaN       NaN       NaN       NaN       NaN  ...   \n",
      "39                       NaN       NaN       NaN  0.818361       NaN  ...   \n",
      "60                  0.998538  0.820070  0.802248  0.741214  0.715091  ...   \n",
      "88                  0.796389  0.754519  0.707278  0.666629  0.649295  ...   \n",
      "116                 0.705447  0.687259  0.662357  0.630863  0.596684  ...   \n",
      "151                 0.677493  0.253914  0.617863  0.591984  0.564580  ...   \n",
      "179                 0.651188  0.626469  0.597294  0.571354  0.544682  ...   \n",
      "207                 0.624882  0.597904  0.572270  0.549748  0.526372  ...   \n",
      "242                 0.604374  0.577641  0.554448  0.531011  0.508916  ...   \n",
      "298                 0.590885  0.566533  0.540349  0.518193  0.499669  ...   \n",
      "396                 0.531743  0.552861  0.492925  0.475591  0.488256  ...   \n",
      "487                 0.402594  0.486883  0.191292  0.482397  0.465032  ...   \n",
      "578                 0.520604  0.384741  0.423834  0.464788  0.449987  ...   \n",
      "606                 0.495824  0.471014  0.456960  0.445028  0.430059  ...   \n",
      "760                 0.460973  0.463110  0.449590  0.437887  0.433767  ...   \n",
      "942                 0.450659  0.460592  0.445486  0.420096  0.411123  ...   \n",
      "\n",
      "strike                 270.0     275.0     280.0     285.0     290.0  \\\n",
      "time_to_expiration                                                     \n",
      "4                        NaN       NaN       NaN       NaN       NaN   \n",
      "11                       NaN       NaN       NaN       NaN       NaN   \n",
      "18                       NaN       NaN       NaN       NaN       NaN   \n",
      "25                  1.897311       NaN  1.838503       NaN  2.093081   \n",
      "32                       NaN       NaN       NaN       NaN       NaN   \n",
      "39                       NaN       NaN       NaN       NaN       NaN   \n",
      "60                  0.827306       NaN  1.213751       NaN       NaN   \n",
      "88                       NaN       NaN       NaN       NaN       NaN   \n",
      "116                 0.695776       NaN  0.893071       NaN  0.961873   \n",
      "151                 0.297859  0.824041  0.292488  0.277351  0.285163   \n",
      "179                 0.235359  0.238289  0.246101  0.125009  0.261726   \n",
      "207                 0.305061  0.231453  0.320563  0.646933  0.657828   \n",
      "242                 0.549214  0.540517  0.459539  0.603214  0.438055   \n",
      "298                 0.548207  0.619556  0.291969  0.501744  0.263923   \n",
      "396                 0.258827  0.240486  0.506795  0.228035  0.512624   \n",
      "487                 0.231880       NaN  0.282844       NaN  0.274055   \n",
      "578                 0.250801  0.259895  0.261177  0.262153  0.263862   \n",
      "606                 0.427710  0.258949  0.390906  0.526479  0.246345   \n",
      "760                 0.258400       NaN  0.257820       NaN  0.268745   \n",
      "942                 0.231697       NaN  0.278114       NaN  0.234291   \n",
      "\n",
      "strike                 295.0     300.0     305.0     310.0     320.0  \n",
      "time_to_expiration                                                    \n",
      "4                        NaN       NaN       NaN       NaN       NaN  \n",
      "11                       NaN       NaN       NaN       NaN       NaN  \n",
      "18                       NaN       NaN       NaN       NaN       NaN  \n",
      "25                       NaN  1.482548       NaN       NaN       NaN  \n",
      "32                       NaN       NaN       NaN       NaN       NaN  \n",
      "39                       NaN       NaN       NaN       NaN       NaN  \n",
      "60                       NaN       NaN       NaN       NaN       NaN  \n",
      "88                       NaN       NaN       NaN       NaN       NaN  \n",
      "116                      NaN  0.466070       NaN       NaN       NaN  \n",
      "151                 0.293952       NaN       NaN       NaN       NaN  \n",
      "179                      NaN  0.269539       NaN       NaN       NaN  \n",
      "207                 0.251961       NaN       NaN       NaN       NaN  \n",
      "242                      NaN  0.327827       NaN  0.344672  0.355963  \n",
      "298                      NaN  0.278328       NaN  0.291023       NaN  \n",
      "396                      NaN  0.364356       NaN  0.590962  0.322852  \n",
      "487                      NaN  0.421408       NaN  0.242195       NaN  \n",
      "578                 0.267097  0.273994  0.275825  0.278205       NaN  \n",
      "606                      NaN  0.342383       NaN  0.501470       NaN  \n",
      "760                      NaN  0.409025       NaN  0.256294       NaN  \n",
      "942                      NaN  0.130593       NaN  0.237373       NaN  \n",
      "\n",
      "[20 rows x 69 columns]\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "Let's now combine the 2 matrices in to one mb_iv\n",
    "The rule here is to take the average of the 2 when the vol is not zero or not n/a\n",
    "'''\n",
    "\n",
    "# First replace zeros with NaN in both matrices\n",
    "call_iv_matrix.replace(0, np.nan, inplace=True)\n",
    "put_iv_matrix.replace(0, np.nan, inplace=True)\n",
    "\n",
    "# Define a custom function to calculate average if neither is zero or NaN\n",
    "def custom_combine(ser1, ser2):\n",
    "    ser1_valid = ser1.notna()\n",
    "    ser2_valid = ser2.notna()\n",
    "    both_valid = ser1_valid & ser2_valid\n",
    "    return pd.Series(np.where(both_valid, (ser1 + ser2)/2, np.where(ser1_valid, ser1, ser2)), index=ser1.index)\n",
    "\n",
    "# Apply the custom function column-wise\n",
    "mb_iv = call_iv_matrix.combine(put_iv_matrix, custom_combine)\n",
    "\n",
    "print(\"Combined implied volatility matrix:\")\n",
    "print(mb_iv)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "4aa370db-653b-48a3-ba45-832c10b8189f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Selected columns from Put implied volatility matrix:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>strike</th>\n",
       "      <th>50.0</th>\n",
       "      <th>55.0</th>\n",
       "      <th>60.0</th>\n",
       "      <th>65.0</th>\n",
       "      <th>70.0</th>\n",
       "      <th>295.0</th>\n",
       "      <th>300.0</th>\n",
       "      <th>305.0</th>\n",
       "      <th>310.0</th>\n",
       "      <th>320.0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time_to_expiration</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.000002</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.187505</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2.617191</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.500002</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.551760</td>\n",
       "      <td>1.382816</td>\n",
       "      <td>1.339847</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.482548</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>1.843751</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>1.304691</td>\n",
       "      <td>0.429693</td>\n",
       "      <td>1.127932</td>\n",
       "      <td>1.142580</td>\n",
       "      <td>0.970951</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>1.052249</td>\n",
       "      <td>0.359381</td>\n",
       "      <td>0.977786</td>\n",
       "      <td>0.405279</td>\n",
       "      <td>0.898929</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.784304</td>\n",
       "      <td>0.758791</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.466070</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.815434</td>\n",
       "      <td>0.291023</td>\n",
       "      <td>0.265632</td>\n",
       "      <td>0.712527</td>\n",
       "      <td>0.293952</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>0.835209</td>\n",
       "      <td>0.297859</td>\n",
       "      <td>0.566411</td>\n",
       "      <td>0.513677</td>\n",
       "      <td>0.503911</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.269539</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>207</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.676639</td>\n",
       "      <td>0.649418</td>\n",
       "      <td>0.251961</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>242</th>\n",
       "      <td>0.752688</td>\n",
       "      <td>0.718387</td>\n",
       "      <td>0.688846</td>\n",
       "      <td>0.654972</td>\n",
       "      <td>0.628239</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.327827</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.344672</td>\n",
       "      <td>0.355963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>0.706058</td>\n",
       "      <td>0.595219</td>\n",
       "      <td>0.646610</td>\n",
       "      <td>0.624027</td>\n",
       "      <td>0.617497</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.278328</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.291023</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>0.665409</td>\n",
       "      <td>0.667057</td>\n",
       "      <td>0.605839</td>\n",
       "      <td>0.571904</td>\n",
       "      <td>0.556737</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.364356</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.590962</td>\n",
       "      <td>0.322852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>487</th>\n",
       "      <td>0.614933</td>\n",
       "      <td>0.537846</td>\n",
       "      <td>0.516362</td>\n",
       "      <td>0.581608</td>\n",
       "      <td>0.522405</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.421408</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.242195</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578</th>\n",
       "      <td>0.606144</td>\n",
       "      <td>0.252693</td>\n",
       "      <td>0.271370</td>\n",
       "      <td>0.512700</td>\n",
       "      <td>0.488653</td>\n",
       "      <td>0.267097</td>\n",
       "      <td>0.273994</td>\n",
       "      <td>0.275825</td>\n",
       "      <td>0.278205</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>0.590885</td>\n",
       "      <td>0.606083</td>\n",
       "      <td>0.546757</td>\n",
       "      <td>0.538701</td>\n",
       "      <td>0.519017</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.342383</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.501470</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>760</th>\n",
       "      <td>0.558415</td>\n",
       "      <td>0.560734</td>\n",
       "      <td>0.510930</td>\n",
       "      <td>0.511449</td>\n",
       "      <td>0.497258</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.409025</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.256294</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942</th>\n",
       "      <td>0.500615</td>\n",
       "      <td>0.518987</td>\n",
       "      <td>0.499517</td>\n",
       "      <td>0.453192</td>\n",
       "      <td>0.466131</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.130593</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.237373</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "strike                 50.0      55.0      60.0      65.0      70.0   \\\n",
       "time_to_expiration                                                     \n",
       "4                   3.000002       NaN       NaN       NaN  2.187505   \n",
       "11                  2.617191       NaN       NaN       NaN  1.500002   \n",
       "18                       NaN       NaN       NaN       NaN       NaN   \n",
       "25                       NaN       NaN  1.551760  1.382816  1.339847   \n",
       "32                  1.843751       NaN       NaN       NaN       NaN   \n",
       "39                       NaN       NaN       NaN       NaN       NaN   \n",
       "60                  1.304691  0.429693  1.127932  1.142580  0.970951   \n",
       "88                  1.052249  0.359381  0.977786  0.405279  0.898929   \n",
       "116                      NaN       NaN       NaN  0.784304  0.758791   \n",
       "151                      NaN  0.815434  0.291023  0.265632  0.712527   \n",
       "179                 0.835209  0.297859  0.566411  0.513677  0.503911   \n",
       "207                      NaN       NaN       NaN  0.676639  0.649418   \n",
       "242                 0.752688  0.718387  0.688846  0.654972  0.628239   \n",
       "298                 0.706058  0.595219  0.646610  0.624027  0.617497   \n",
       "396                 0.665409  0.667057  0.605839  0.571904  0.556737   \n",
       "487                 0.614933  0.537846  0.516362  0.581608  0.522405   \n",
       "578                 0.606144  0.252693  0.271370  0.512700  0.488653   \n",
       "606                 0.590885  0.606083  0.546757  0.538701  0.519017   \n",
       "760                 0.558415  0.560734  0.510930  0.511449  0.497258   \n",
       "942                 0.500615  0.518987  0.499517  0.453192  0.466131   \n",
       "\n",
       "strike                 295.0     300.0     305.0     310.0     320.0  \n",
       "time_to_expiration                                                    \n",
       "4                        NaN       NaN       NaN       NaN       NaN  \n",
       "11                       NaN       NaN       NaN       NaN       NaN  \n",
       "18                       NaN       NaN       NaN       NaN       NaN  \n",
       "25                       NaN  1.482548       NaN       NaN       NaN  \n",
       "32                       NaN       NaN       NaN       NaN       NaN  \n",
       "39                       NaN       NaN       NaN       NaN       NaN  \n",
       "60                       NaN       NaN       NaN       NaN       NaN  \n",
       "88                       NaN       NaN       NaN       NaN       NaN  \n",
       "116                      NaN  0.466070       NaN       NaN       NaN  \n",
       "151                 0.293952       NaN       NaN       NaN       NaN  \n",
       "179                      NaN  0.269539       NaN       NaN       NaN  \n",
       "207                 0.251961       NaN       NaN       NaN       NaN  \n",
       "242                      NaN  0.327827       NaN  0.344672  0.355963  \n",
       "298                      NaN  0.278328       NaN  0.291023       NaN  \n",
       "396                      NaN  0.364356       NaN  0.590962  0.322852  \n",
       "487                      NaN  0.421408       NaN  0.242195       NaN  \n",
       "578                 0.267097  0.273994  0.275825  0.278205       NaN  \n",
       "606                      NaN  0.342383       NaN  0.501470       NaN  \n",
       "760                      NaN  0.409025       NaN  0.256294       NaN  \n",
       "942                      NaN  0.130593       NaN  0.237373       NaN  "
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Select first 5 and last 5 columns of implied volatility matrix\n",
    "iv_selected = pd.concat([mb_iv.iloc[:, :5], mb_iv.iloc[:, -5:]], axis=1)\n",
    "print(\"\\nSelected columns from Put implied volatility matrix:\")\n",
    "iv_selected"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f89e807-034b-427d-81a7-f4f530c849ba",
   "metadata": {},
   "source": [
    "### Interest Rates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9e8b85fb-dc01-4829-8777-7fa20a9778d3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   US_Treasury_Rates  Yield\n",
      "0                 1m   5.62\n",
      "1                 2m   5.27\n",
      "2                 3m   5.29\n",
      "3                 4m   5.46\n",
      "4                 6m   5.36\n",
      "5                 1y   5.02\n",
      "6                 2y   4.28\n",
      "7                 3y   3.98\n",
      "8                 5y   3.76\n",
      "9                 7y   3.74\n",
      "10               10y   3.70\n",
      "11               20y   4.07\n",
      "12               30y   3.95\n"
     ]
    }
   ],
   "source": [
    "# Copy Sources Data DataFrame\n",
    "mb_interest_rates = mb_src_ir.copy()\n",
    "\n",
    "# Print the updated DataFrame with formatted index\n",
    "print(mb_interest_rates)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6c909947-3850-4153-8cb3-ce0e6cb86e53",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "df600856-e981-45a3-b824-bcf48e080e0a",
   "metadata": {},
   "source": [
    "### Preparing Data for Model Development and Testing"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "929cb602-3835-4cb7-9b65-fbf0d7e10628",
   "metadata": {},
   "source": [
    "#### Preparing the underlying price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "0440dec5-2e82-4cb9-9c08-94c6ce217354",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The price of AAPL on 2023-05-19 was 175.16000366210938\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "175.16000366210938"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price_on_date = mb_prices.loc['2023-05-19', 'AAPL']\n",
    "print(f\"The price of AAPL on 2023-05-19 was {price_on_date}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d90c5e39-c223-426e-8caa-f7ea7b027b90",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "d8e1de66-6950-4e4e-9475-e77bf5cb9eab",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Preparing the options static data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "3f64cf29-1edc-4dfe-8e89-4eceae7dd686",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>contractSymbol</th>\n",
       "      <th>lastTradeDate</th>\n",
       "      <th>strike</th>\n",
       "      <th>lastPrice</th>\n",
       "      <th>impliedVolatility</th>\n",
       "      <th>inTheMoney</th>\n",
       "      <th>currency</th>\n",
       "      <th>OptionType</th>\n",
       "      <th>expirationDate</th>\n",
       "      <th>time_to_expiration</th>\n",
       "      <th>OptionStyle</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AAPL230526C00095000</td>\n",
       "      <td>2023-05-19 19:36:18+00:00</td>\n",
       "      <td>95.0</td>\n",
       "      <td>80.27</td>\n",
       "      <td>1.812501</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AAPL230526C00100000</td>\n",
       "      <td>2023-05-17 13:59:34+00:00</td>\n",
       "      <td>100.0</td>\n",
       "      <td>75.32</td>\n",
       "      <td>2.871097</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>AAPL230526C00110000</td>\n",
       "      <td>2023-05-16 18:17:19+00:00</td>\n",
       "      <td>110.0</td>\n",
       "      <td>62.18</td>\n",
       "      <td>2.478519</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>AAPL230526C00115000</td>\n",
       "      <td>2023-05-08 15:00:05+00:00</td>\n",
       "      <td>115.0</td>\n",
       "      <td>58.70</td>\n",
       "      <td>1.539065</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>AAPL230526C00120000</td>\n",
       "      <td>2023-05-17 19:25:47+00:00</td>\n",
       "      <td>120.0</td>\n",
       "      <td>52.52</td>\n",
       "      <td>1.332035</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1628</th>\n",
       "      <td>AAPL251219P00260000</td>\n",
       "      <td>2023-05-15 18:24:01+00:00</td>\n",
       "      <td>260.0</td>\n",
       "      <td>86.91</td>\n",
       "      <td>0.168923</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-12-19</td>\n",
       "      <td>942</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1629</th>\n",
       "      <td>AAPL251219P00270000</td>\n",
       "      <td>2023-05-05 14:01:40+00:00</td>\n",
       "      <td>270.0</td>\n",
       "      <td>96.76</td>\n",
       "      <td>0.180520</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-12-19</td>\n",
       "      <td>942</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1630</th>\n",
       "      <td>AAPL251219P00290000</td>\n",
       "      <td>2023-05-11 17:03:36+00:00</td>\n",
       "      <td>290.0</td>\n",
       "      <td>116.36</td>\n",
       "      <td>0.200753</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-12-19</td>\n",
       "      <td>942</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1631</th>\n",
       "      <td>AAPL251219P00300000</td>\n",
       "      <td>2023-04-19 13:31:50+00:00</td>\n",
       "      <td>300.0</td>\n",
       "      <td>134.00</td>\n",
       "      <td>0.000010</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-12-19</td>\n",
       "      <td>942</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1632</th>\n",
       "      <td>AAPL251219P00310000</td>\n",
       "      <td>2023-05-15 18:24:01+00:00</td>\n",
       "      <td>310.0</td>\n",
       "      <td>139.21</td>\n",
       "      <td>0.220070</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-12-19</td>\n",
       "      <td>942</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1633 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           contractSymbol              lastTradeDate  strike  lastPrice  \\\n",
       "0     AAPL230526C00095000  2023-05-19 19:36:18+00:00    95.0      80.27   \n",
       "1     AAPL230526C00100000  2023-05-17 13:59:34+00:00   100.0      75.32   \n",
       "2     AAPL230526C00110000  2023-05-16 18:17:19+00:00   110.0      62.18   \n",
       "3     AAPL230526C00115000  2023-05-08 15:00:05+00:00   115.0      58.70   \n",
       "4     AAPL230526C00120000  2023-05-17 19:25:47+00:00   120.0      52.52   \n",
       "...                   ...                        ...     ...        ...   \n",
       "1628  AAPL251219P00260000  2023-05-15 18:24:01+00:00   260.0      86.91   \n",
       "1629  AAPL251219P00270000  2023-05-05 14:01:40+00:00   270.0      96.76   \n",
       "1630  AAPL251219P00290000  2023-05-11 17:03:36+00:00   290.0     116.36   \n",
       "1631  AAPL251219P00300000  2023-04-19 13:31:50+00:00   300.0     134.00   \n",
       "1632  AAPL251219P00310000  2023-05-15 18:24:01+00:00   310.0     139.21   \n",
       "\n",
       "      impliedVolatility  inTheMoney currency OptionType expirationDate  \\\n",
       "0              1.812501        True      USD       Call     2023-05-26   \n",
       "1              2.871097        True      USD       Call     2023-05-26   \n",
       "2              2.478519        True      USD       Call     2023-05-26   \n",
       "3              1.539065        True      USD       Call     2023-05-26   \n",
       "4              1.332035        True      USD       Call     2023-05-26   \n",
       "...                 ...         ...      ...        ...            ...   \n",
       "1628           0.168923        True      USD        Put     2025-12-19   \n",
       "1629           0.180520        True      USD        Put     2025-12-19   \n",
       "1630           0.200753        True      USD        Put     2025-12-19   \n",
       "1631           0.000010        True      USD        Put     2025-12-19   \n",
       "1632           0.220070        True      USD        Put     2025-12-19   \n",
       "\n",
       "      time_to_expiration OptionStyle  \n",
       "0                      4    American  \n",
       "1                      4    American  \n",
       "2                      4    American  \n",
       "3                      4    American  \n",
       "4                      4    American  \n",
       "...                  ...         ...  \n",
       "1628                 942    American  \n",
       "1629                 942    American  \n",
       "1630                 942    American  \n",
       "1631                 942    American  \n",
       "1632                 942    American  \n",
       "\n",
       "[1633 rows x 11 columns]"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# First, make a copy of your DataFrame\n",
    "mb_options_copy = mb_options.copy()\n",
    "\n",
    "# Add new column 'OptionStyle' and set all its values to 'American'\n",
    "mb_options_copy['OptionStyle'] = 'American'\n",
    "\n",
    "mb_options_copy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "2155b193-165e-4caa-93c4-bb5755ce1e0f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['contractSymbol', 'lastTradeDate', 'strike', 'lastPrice',\n",
      "       'impliedVolatility', 'inTheMoney', 'currency', 'OptionType',\n",
      "       'expirationDate', 'time_to_expiration', 'OptionStyle'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "print(mb_options_copy.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "fb28653e-0dd2-40c0-8725-818b752153ce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "strike: [ 95.  100.  110.  115.  120.  125.  130.  135.  140.  145.  147.  149.\n",
      " 150.  152.5 155.  157.5 160.  162.5 165.  167.5 170.  172.5 175.  177.5\n",
      " 180.  182.5 185.  187.5 190.  192.5 195.  197.5 200.  202.5 205.  210.\n",
      " 215.  220.  225.  230.  240.  250.   50.   70.   90.  105.  146.  148.\n",
      "  85.  245.  235.   60.   65.   75.   80.  255.  260.  270.  280.  290.\n",
      " 300.   55.  265.  275.  285.  295.  310.  320.  305. ]\n",
      "inTheMoney: [ True False]\n",
      "currency: ['USD']\n",
      "OptionType: ['Call' 'Put']\n",
      "time_to_expiration: [  4  11  18  25  32  39  60  88 116 151 179 207 242 298 396 487 578 606\n",
      " 760 942]\n",
      "OptionStyle: ['American']\n"
     ]
    }
   ],
   "source": [
    "# The columns we are interested in.\n",
    "columns_to_check = ['strike', 'inTheMoney', 'currency', 'OptionType', 'time_to_expiration', 'OptionStyle']\n",
    "\n",
    "for column in columns_to_check:\n",
    "    print(f\"{column}: {mb_options_copy[column].unique()}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "d5ce2806-ce85-4969-adf0-7f18556253f9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "OptionType  Call   Put\n",
      "strike                \n",
      "50.0        11.0  14.0\n",
      "55.0        11.0  12.0\n",
      "60.0        11.0  13.0\n",
      "65.0        13.0  15.0\n",
      "70.0        13.0  17.0\n",
      "...          ...   ...\n",
      "295.0        3.0   NaN\n",
      "300.0       11.0   8.0\n",
      "305.0        1.0   NaN\n",
      "310.0        8.0   5.0\n",
      "320.0        2.0   2.0\n",
      "\n",
      "[69 rows x 2 columns]\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "# Display up to 500 rows and 500 columns\n",
    "#pd.set_option('display.max_rows', 500)\n",
    "#pd.set_option('display.max_columns', 500)\n",
    "\n",
    "pivot_table = mb_options_copy.pivot_table(index='strike', \n",
    "                                          columns='OptionType', \n",
    "                                          values='contractSymbol', \n",
    "                                          aggfunc='count')\n",
    "\n",
    "print(pivot_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "57664b77-4bfb-400c-96fc-2dd47efead49",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "11199dff-cad0-4ff5-8e48-5efbf2f6bce6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "strike      50.0   55.0   60.0   65.0   70.0   75.0   80.0   85.0   90.0   \\\n",
      "OptionType                                                                  \n",
      "Call         11.0   11.0   11.0   13.0   13.0   14.0   15.0   15.0   16.0   \n",
      "Put          14.0   12.0   13.0   15.0   17.0   15.0   15.0   15.0   19.0   \n",
      "\n",
      "strike      95.0   100.0  105.0  110.0  115.0  120.0  125.0  130.0  135.0  \\\n",
      "OptionType                                                                  \n",
      "Call         16.0   18.0   15.0   20.0   17.0   17.0   18.0   20.0   20.0   \n",
      "Put          18.0   20.0   20.0   20.0   20.0   20.0   20.0   20.0   20.0   \n",
      "\n",
      "strike      140.0  145.0  146.0  147.0  148.0  149.0  150.0  152.5  155.0  \\\n",
      "OptionType                                                                  \n",
      "Call         20.0   20.0    NaN    1.0    NaN    1.0   20.0    2.0   20.0   \n",
      "Put          20.0   20.0    1.0    1.0    1.0    1.0   20.0    2.0   20.0   \n",
      "\n",
      "strike      157.5  160.0  162.5  165.0  167.5  170.0  172.5  175.0  177.5  \\\n",
      "OptionType                                                                  \n",
      "Call          2.0   20.0    2.0   20.0    2.0   20.0    2.0   20.0    2.0   \n",
      "Put           2.0   20.0    2.0   20.0    2.0   20.0    2.0   20.0    2.0   \n",
      "\n",
      "strike      180.0  182.5  185.0  187.5  190.0  192.5  195.0  197.5  200.0  \\\n",
      "OptionType                                                                  \n",
      "Call         20.0    2.0   20.0    2.0   20.0    2.0   20.0    2.0   20.0   \n",
      "Put          20.0    2.0   20.0    1.0   20.0    NaN   20.0    NaN   20.0   \n",
      "\n",
      "strike      202.5  205.0  210.0  215.0  220.0  225.0  230.0  235.0  240.0  \\\n",
      "OptionType                                                                  \n",
      "Call          2.0   20.0   19.0   17.0   19.0   18.0   18.0   15.0   17.0   \n",
      "Put           1.0   16.0   18.0   12.0   15.0    9.0   11.0    8.0    9.0   \n",
      "\n",
      "strike      245.0  250.0  255.0  260.0  265.0  270.0  275.0  280.0  285.0  \\\n",
      "OptionType                                                                  \n",
      "Call         16.0   17.0   11.0   14.0    9.0   14.0    8.0   14.0    8.0   \n",
      "Put           6.0   13.0    6.0    9.0    4.0    9.0    4.0    9.0    4.0   \n",
      "\n",
      "strike      290.0  295.0  300.0  305.0  310.0  320.0  \n",
      "OptionType                                            \n",
      "Call         13.0    3.0   11.0    1.0    8.0    2.0  \n",
      "Put           7.0    NaN    8.0    NaN    5.0    2.0  \n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "# Display up to 500 rows and 500 columns\n",
    "pd.set_option('display.max_rows', 500)\n",
    "pd.set_option('display.max_columns', 500)\n",
    "\n",
    "pivot_table = mb_options_copy.pivot_table(index='OptionType', \n",
    "                                          columns='strike', \n",
    "                                          values='contractSymbol', \n",
    "                                          aggfunc='count')\n",
    "\n",
    "print(pivot_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "52c14216-0ab2-4a39-9953-79d86640480c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# To reset pandas' display options to their defaults\n",
    "import pandas as pd\n",
    "\n",
    "pd.reset_option('display.max_rows')\n",
    "pd.reset_option('display.max_columns')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "fbe2bc53-548f-4580-af76-40c03114209f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>contractSymbol</th>\n",
       "      <th>lastTradeDate</th>\n",
       "      <th>strike</th>\n",
       "      <th>lastPrice</th>\n",
       "      <th>impliedVolatility</th>\n",
       "      <th>inTheMoney</th>\n",
       "      <th>currency</th>\n",
       "      <th>OptionType</th>\n",
       "      <th>expirationDate</th>\n",
       "      <th>time_to_expiration</th>\n",
       "      <th>OptionStyle</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1444</th>\n",
       "      <td>AAPL250117P00270000</td>\n",
       "      <td>2022-09-21 15:51:08+00:00</td>\n",
       "      <td>270.0</td>\n",
       "      <td>113.62</td>\n",
       "      <td>0.611363</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-01-17</td>\n",
       "      <td>606</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>621</th>\n",
       "      <td>AAPL230915P00270000</td>\n",
       "      <td>2022-09-29 18:49:54+00:00</td>\n",
       "      <td>270.0</td>\n",
       "      <td>128.77</td>\n",
       "      <td>1.107365</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2023-09-15</td>\n",
       "      <td>116</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1174</th>\n",
       "      <td>AAPL240621P00310000</td>\n",
       "      <td>2022-10-07 15:12:54+00:00</td>\n",
       "      <td>310.0</td>\n",
       "      <td>168.53</td>\n",
       "      <td>0.931672</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2024-06-21</td>\n",
       "      <td>396</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1172</th>\n",
       "      <td>AAPL240621P00290000</td>\n",
       "      <td>2022-10-13 14:30:33+00:00</td>\n",
       "      <td>290.0</td>\n",
       "      <td>154.38</td>\n",
       "      <td>0.736056</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2024-06-21</td>\n",
       "      <td>396</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>971</th>\n",
       "      <td>AAPL240119P00270000</td>\n",
       "      <td>2022-10-14 16:09:47+00:00</td>\n",
       "      <td>270.0</td>\n",
       "      <td>130.59</td>\n",
       "      <td>0.882112</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2024-01-19</td>\n",
       "      <td>242</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>968</th>\n",
       "      <td>AAPL240119P00255000</td>\n",
       "      <td>2023-04-13 19:33:43+00:00</td>\n",
       "      <td>255.0</td>\n",
       "      <td>89.50</td>\n",
       "      <td>0.367072</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2024-01-19</td>\n",
       "      <td>242</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>464</th>\n",
       "      <td>AAPL230721P00250000</td>\n",
       "      <td>2023-04-14 16:12:55+00:00</td>\n",
       "      <td>250.0</td>\n",
       "      <td>85.39</td>\n",
       "      <td>0.688724</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2023-07-21</td>\n",
       "      <td>60</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1437</th>\n",
       "      <td>AAPL250117P00235000</td>\n",
       "      <td>2023-04-14 18:14:12+00:00</td>\n",
       "      <td>235.0</td>\n",
       "      <td>70.55</td>\n",
       "      <td>0.219765</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2025-01-17</td>\n",
       "      <td>606</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>422</th>\n",
       "      <td>AAPL230721C00270000</td>\n",
       "      <td>2023-04-17 13:44:00+00:00</td>\n",
       "      <td>270.0</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.250007</td>\n",
       "      <td>False</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-07-21</td>\n",
       "      <td>60</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153</th>\n",
       "      <td>AAPL230602P00195000</td>\n",
       "      <td>2023-04-17 14:47:30+00:00</td>\n",
       "      <td>195.0</td>\n",
       "      <td>30.75</td>\n",
       "      <td>0.650394</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2023-06-02</td>\n",
       "      <td>11</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           contractSymbol              lastTradeDate  strike  lastPrice  \\\n",
       "1444  AAPL250117P00270000  2022-09-21 15:51:08+00:00   270.0     113.62   \n",
       "621   AAPL230915P00270000  2022-09-29 18:49:54+00:00   270.0     128.77   \n",
       "1174  AAPL240621P00310000  2022-10-07 15:12:54+00:00   310.0     168.53   \n",
       "1172  AAPL240621P00290000  2022-10-13 14:30:33+00:00   290.0     154.38   \n",
       "971   AAPL240119P00270000  2022-10-14 16:09:47+00:00   270.0     130.59   \n",
       "...                   ...                        ...     ...        ...   \n",
       "968   AAPL240119P00255000  2023-04-13 19:33:43+00:00   255.0      89.50   \n",
       "464   AAPL230721P00250000  2023-04-14 16:12:55+00:00   250.0      85.39   \n",
       "1437  AAPL250117P00235000  2023-04-14 18:14:12+00:00   235.0      70.55   \n",
       "422   AAPL230721C00270000  2023-04-17 13:44:00+00:00   270.0       0.01   \n",
       "153   AAPL230602P00195000  2023-04-17 14:47:30+00:00   195.0      30.75   \n",
       "\n",
       "      impliedVolatility  inTheMoney currency OptionType expirationDate  \\\n",
       "1444           0.611363        True      USD        Put     2025-01-17   \n",
       "621            1.107365        True      USD        Put     2023-09-15   \n",
       "1174           0.931672        True      USD        Put     2024-06-21   \n",
       "1172           0.736056        True      USD        Put     2024-06-21   \n",
       "971            0.882112        True      USD        Put     2024-01-19   \n",
       "...                 ...         ...      ...        ...            ...   \n",
       "968            0.367072        True      USD        Put     2024-01-19   \n",
       "464            0.688724        True      USD        Put     2023-07-21   \n",
       "1437           0.219765        True      USD        Put     2025-01-17   \n",
       "422            0.250007       False      USD       Call     2023-07-21   \n",
       "153            0.650394        True      USD        Put     2023-06-02   \n",
       "\n",
       "      time_to_expiration OptionStyle  \n",
       "1444                 606    American  \n",
       "621                  116    American  \n",
       "1174                 396    American  \n",
       "1172                 396    American  \n",
       "971                  242    American  \n",
       "...                  ...         ...  \n",
       "968                  242    American  \n",
       "464                   60    American  \n",
       "1437                 606    American  \n",
       "422                   60    American  \n",
       "153                   11    American  \n",
       "\n",
       "[100 rows x 11 columns]"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mb_options_sorted = mb_options_copy.sort_values(by='lastTradeDate')\n",
    "mb_options_sorted.head(100)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "15cdc985-ab56-4fb1-906d-d1cfcf9ca93e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 55.  60.  65.  80.  85. 105. 115. 195. 215. 220. 225. 230. 235. 240.\n",
      " 245. 250. 255. 260. 265. 270. 275. 280. 285. 290. 300. 310. 320.]\n"
     ]
    }
   ],
   "source": [
    "unique_strikes_first = mb_options_sorted['strike'].head(100).unique()\n",
    "unique_strikes_first.sort()\n",
    "print(unique_strikes_first)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "598c9f4a-c8ea-4c33-a652-4c3a22571628",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>contractSymbol</th>\n",
       "      <th>lastTradeDate</th>\n",
       "      <th>strike</th>\n",
       "      <th>lastPrice</th>\n",
       "      <th>impliedVolatility</th>\n",
       "      <th>inTheMoney</th>\n",
       "      <th>currency</th>\n",
       "      <th>OptionType</th>\n",
       "      <th>expirationDate</th>\n",
       "      <th>time_to_expiration</th>\n",
       "      <th>OptionStyle</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>AAPL230526C00175000</td>\n",
       "      <td>2023-05-19 19:59:59+00:00</td>\n",
       "      <td>175.0</td>\n",
       "      <td>1.77</td>\n",
       "      <td>0.197518</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>231</th>\n",
       "      <td>AAPL230616C00175000</td>\n",
       "      <td>2023-05-19 19:59:58+00:00</td>\n",
       "      <td>175.0</td>\n",
       "      <td>4.20</td>\n",
       "      <td>0.219490</td>\n",
       "      <td>True</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-06-16</td>\n",
       "      <td>25</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>AAPL230602C00177500</td>\n",
       "      <td>2023-05-19 19:59:58+00:00</td>\n",
       "      <td>177.5</td>\n",
       "      <td>1.44</td>\n",
       "      <td>0.193734</td>\n",
       "      <td>False</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-06-02</td>\n",
       "      <td>11</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>AAPL230526P00175000</td>\n",
       "      <td>2023-05-19 19:59:58+00:00</td>\n",
       "      <td>175.0</td>\n",
       "      <td>1.45</td>\n",
       "      <td>0.171883</td>\n",
       "      <td>False</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>AAPL230526P00172500</td>\n",
       "      <td>2023-05-19 19:59:57+00:00</td>\n",
       "      <td>172.5</td>\n",
       "      <td>0.66</td>\n",
       "      <td>0.187020</td>\n",
       "      <td>False</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2023-05-26</td>\n",
       "      <td>4</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>371</th>\n",
       "      <td>AAPL230630P00165000</td>\n",
       "      <td>2023-05-19 19:58:04+00:00</td>\n",
       "      <td>165.0</td>\n",
       "      <td>1.40</td>\n",
       "      <td>0.220711</td>\n",
       "      <td>False</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2023-06-30</td>\n",
       "      <td>39</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>353</th>\n",
       "      <td>AAPL230630C00190000</td>\n",
       "      <td>2023-05-19 19:58:04+00:00</td>\n",
       "      <td>190.0</td>\n",
       "      <td>0.40</td>\n",
       "      <td>0.174569</td>\n",
       "      <td>False</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-06-30</td>\n",
       "      <td>39</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>370</th>\n",
       "      <td>AAPL230630P00160000</td>\n",
       "      <td>2023-05-19 19:58:04+00:00</td>\n",
       "      <td>160.0</td>\n",
       "      <td>0.87</td>\n",
       "      <td>0.242683</td>\n",
       "      <td>False</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2023-06-30</td>\n",
       "      <td>39</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>445</th>\n",
       "      <td>AAPL230721P00155000</td>\n",
       "      <td>2023-05-19 19:58:04+00:00</td>\n",
       "      <td>155.0</td>\n",
       "      <td>1.02</td>\n",
       "      <td>0.253914</td>\n",
       "      <td>False</td>\n",
       "      <td>USD</td>\n",
       "      <td>Put</td>\n",
       "      <td>2023-07-21</td>\n",
       "      <td>60</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>407</th>\n",
       "      <td>AAPL230721C00185000</td>\n",
       "      <td>2023-05-19 19:57:59+00:00</td>\n",
       "      <td>185.0</td>\n",
       "      <td>1.96</td>\n",
       "      <td>0.189095</td>\n",
       "      <td>False</td>\n",
       "      <td>USD</td>\n",
       "      <td>Call</td>\n",
       "      <td>2023-07-21</td>\n",
       "      <td>60</td>\n",
       "      <td>American</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          contractSymbol              lastTradeDate  strike  lastPrice  \\\n",
       "22   AAPL230526C00175000  2023-05-19 19:59:59+00:00   175.0       1.77   \n",
       "231  AAPL230616C00175000  2023-05-19 19:59:58+00:00   175.0       4.20   \n",
       "104  AAPL230602C00177500  2023-05-19 19:59:58+00:00   177.5       1.44   \n",
       "70   AAPL230526P00175000  2023-05-19 19:59:58+00:00   175.0       1.45   \n",
       "69   AAPL230526P00172500  2023-05-19 19:59:57+00:00   172.5       0.66   \n",
       "..                   ...                        ...     ...        ...   \n",
       "371  AAPL230630P00165000  2023-05-19 19:58:04+00:00   165.0       1.40   \n",
       "353  AAPL230630C00190000  2023-05-19 19:58:04+00:00   190.0       0.40   \n",
       "370  AAPL230630P00160000  2023-05-19 19:58:04+00:00   160.0       0.87   \n",
       "445  AAPL230721P00155000  2023-05-19 19:58:04+00:00   155.0       1.02   \n",
       "407  AAPL230721C00185000  2023-05-19 19:57:59+00:00   185.0       1.96   \n",
       "\n",
       "     impliedVolatility  inTheMoney currency OptionType expirationDate  \\\n",
       "22            0.197518        True      USD       Call     2023-05-26   \n",
       "231           0.219490        True      USD       Call     2023-06-16   \n",
       "104           0.193734       False      USD       Call     2023-06-02   \n",
       "70            0.171883       False      USD        Put     2023-05-26   \n",
       "69            0.187020       False      USD        Put     2023-05-26   \n",
       "..                 ...         ...      ...        ...            ...   \n",
       "371           0.220711       False      USD        Put     2023-06-30   \n",
       "353           0.174569       False      USD       Call     2023-06-30   \n",
       "370           0.242683       False      USD        Put     2023-06-30   \n",
       "445           0.253914       False      USD        Put     2023-07-21   \n",
       "407           0.189095       False      USD       Call     2023-07-21   \n",
       "\n",
       "     time_to_expiration OptionStyle  \n",
       "22                    4    American  \n",
       "231                  25    American  \n",
       "104                  11    American  \n",
       "70                    4    American  \n",
       "69                    4    American  \n",
       "..                  ...         ...  \n",
       "371                  39    American  \n",
       "353                  39    American  \n",
       "370                  39    American  \n",
       "445                  60    American  \n",
       "407                  60    American  \n",
       "\n",
       "[100 rows x 11 columns]"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mb_options_sorted = mb_options_copy.sort_values(by='lastTradeDate', ascending=False)\n",
    "mb_options_sorted.head(100)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a85bc1ab-e39e-4c5d-9a5a-b913127d3b42",
   "metadata": {},
   "source": [
    "#### Preparing the volatilities grid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "47ec3e58-9b2e-4ec0-b4bf-f6f6b759fadb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>strike</th>\n",
       "      <th>50.0</th>\n",
       "      <th>55.0</th>\n",
       "      <th>60.0</th>\n",
       "      <th>65.0</th>\n",
       "      <th>70.0</th>\n",
       "      <th>75.0</th>\n",
       "      <th>80.0</th>\n",
       "      <th>85.0</th>\n",
       "      <th>90.0</th>\n",
       "      <th>95.0</th>\n",
       "      <th>...</th>\n",
       "      <th>270.0</th>\n",
       "      <th>275.0</th>\n",
       "      <th>280.0</th>\n",
       "      <th>285.0</th>\n",
       "      <th>290.0</th>\n",
       "      <th>295.0</th>\n",
       "      <th>300.0</th>\n",
       "      <th>305.0</th>\n",
       "      <th>310.0</th>\n",
       "      <th>320.0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time_to_expiration</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.000002</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.187505</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.625002</td>\n",
       "      <td>1.656252</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2.617191</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.500002</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.765626</td>\n",
       "      <td>1.503909</td>\n",
       "      <td>1.332035</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.164067</td>\n",
       "      <td>1.136723</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.551760</td>\n",
       "      <td>1.382816</td>\n",
       "      <td>1.339847</td>\n",
       "      <td>1.313480</td>\n",
       "      <td>1.189943</td>\n",
       "      <td>1.103520</td>\n",
       "      <td>1.115727</td>\n",
       "      <td>0.956058</td>\n",
       "      <td>...</td>\n",
       "      <td>1.897311</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.838503</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.093081</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.482548</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>1.843751</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.818361</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>1.304691</td>\n",
       "      <td>0.429693</td>\n",
       "      <td>1.127932</td>\n",
       "      <td>1.142580</td>\n",
       "      <td>0.970951</td>\n",
       "      <td>0.998538</td>\n",
       "      <td>0.820070</td>\n",
       "      <td>0.802248</td>\n",
       "      <td>0.741214</td>\n",
       "      <td>0.715091</td>\n",
       "      <td>...</td>\n",
       "      <td>0.827306</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.213751</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>1.052249</td>\n",
       "      <td>0.359381</td>\n",
       "      <td>0.977786</td>\n",
       "      <td>0.405279</td>\n",
       "      <td>0.898929</td>\n",
       "      <td>0.796389</td>\n",
       "      <td>0.754519</td>\n",
       "      <td>0.707278</td>\n",
       "      <td>0.666629</td>\n",
       "      <td>0.649295</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.784304</td>\n",
       "      <td>0.758791</td>\n",
       "      <td>0.705447</td>\n",
       "      <td>0.687259</td>\n",
       "      <td>0.662357</td>\n",
       "      <td>0.630863</td>\n",
       "      <td>0.596684</td>\n",
       "      <td>...</td>\n",
       "      <td>0.695776</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.893071</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.961873</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.466070</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.815434</td>\n",
       "      <td>0.291023</td>\n",
       "      <td>0.265632</td>\n",
       "      <td>0.712527</td>\n",
       "      <td>0.677493</td>\n",
       "      <td>0.253914</td>\n",
       "      <td>0.617863</td>\n",
       "      <td>0.591984</td>\n",
       "      <td>0.564580</td>\n",
       "      <td>...</td>\n",
       "      <td>0.297859</td>\n",
       "      <td>0.824041</td>\n",
       "      <td>0.292488</td>\n",
       "      <td>0.277351</td>\n",
       "      <td>0.285163</td>\n",
       "      <td>0.293952</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>0.835209</td>\n",
       "      <td>0.297859</td>\n",
       "      <td>0.566411</td>\n",
       "      <td>0.513677</td>\n",
       "      <td>0.503911</td>\n",
       "      <td>0.651188</td>\n",
       "      <td>0.626469</td>\n",
       "      <td>0.597294</td>\n",
       "      <td>0.571354</td>\n",
       "      <td>0.544682</td>\n",
       "      <td>...</td>\n",
       "      <td>0.235359</td>\n",
       "      <td>0.238289</td>\n",
       "      <td>0.246101</td>\n",
       "      <td>0.125009</td>\n",
       "      <td>0.261726</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.269539</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>207</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.676639</td>\n",
       "      <td>0.649418</td>\n",
       "      <td>0.624882</td>\n",
       "      <td>0.597904</td>\n",
       "      <td>0.572270</td>\n",
       "      <td>0.549748</td>\n",
       "      <td>0.526372</td>\n",
       "      <td>...</td>\n",
       "      <td>0.305061</td>\n",
       "      <td>0.231453</td>\n",
       "      <td>0.320563</td>\n",
       "      <td>0.646933</td>\n",
       "      <td>0.657828</td>\n",
       "      <td>0.251961</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>242</th>\n",
       "      <td>0.752688</td>\n",
       "      <td>0.718387</td>\n",
       "      <td>0.688846</td>\n",
       "      <td>0.654972</td>\n",
       "      <td>0.628239</td>\n",
       "      <td>0.604374</td>\n",
       "      <td>0.577641</td>\n",
       "      <td>0.554448</td>\n",
       "      <td>0.531011</td>\n",
       "      <td>0.508916</td>\n",
       "      <td>...</td>\n",
       "      <td>0.549214</td>\n",
       "      <td>0.540517</td>\n",
       "      <td>0.459539</td>\n",
       "      <td>0.603214</td>\n",
       "      <td>0.438055</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.327827</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.344672</td>\n",
       "      <td>0.355963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>0.706058</td>\n",
       "      <td>0.595219</td>\n",
       "      <td>0.646610</td>\n",
       "      <td>0.624027</td>\n",
       "      <td>0.617497</td>\n",
       "      <td>0.590885</td>\n",
       "      <td>0.566533</td>\n",
       "      <td>0.540349</td>\n",
       "      <td>0.518193</td>\n",
       "      <td>0.499669</td>\n",
       "      <td>...</td>\n",
       "      <td>0.548207</td>\n",
       "      <td>0.619556</td>\n",
       "      <td>0.291969</td>\n",
       "      <td>0.501744</td>\n",
       "      <td>0.263923</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.278328</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.291023</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>0.665409</td>\n",
       "      <td>0.667057</td>\n",
       "      <td>0.605839</td>\n",
       "      <td>0.571904</td>\n",
       "      <td>0.556737</td>\n",
       "      <td>0.531743</td>\n",
       "      <td>0.552861</td>\n",
       "      <td>0.492925</td>\n",
       "      <td>0.475591</td>\n",
       "      <td>0.488256</td>\n",
       "      <td>...</td>\n",
       "      <td>0.258827</td>\n",
       "      <td>0.240486</td>\n",
       "      <td>0.506795</td>\n",
       "      <td>0.228035</td>\n",
       "      <td>0.512624</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.364356</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.590962</td>\n",
       "      <td>0.322852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>487</th>\n",
       "      <td>0.614933</td>\n",
       "      <td>0.537846</td>\n",
       "      <td>0.516362</td>\n",
       "      <td>0.581608</td>\n",
       "      <td>0.522405</td>\n",
       "      <td>0.402594</td>\n",
       "      <td>0.486883</td>\n",
       "      <td>0.191292</td>\n",
       "      <td>0.482397</td>\n",
       "      <td>0.465032</td>\n",
       "      <td>...</td>\n",
       "      <td>0.231880</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.282844</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.274055</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.421408</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.242195</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578</th>\n",
       "      <td>0.606144</td>\n",
       "      <td>0.252693</td>\n",
       "      <td>0.271370</td>\n",
       "      <td>0.512700</td>\n",
       "      <td>0.488653</td>\n",
       "      <td>0.520604</td>\n",
       "      <td>0.384741</td>\n",
       "      <td>0.423834</td>\n",
       "      <td>0.464788</td>\n",
       "      <td>0.449987</td>\n",
       "      <td>...</td>\n",
       "      <td>0.250801</td>\n",
       "      <td>0.259895</td>\n",
       "      <td>0.261177</td>\n",
       "      <td>0.262153</td>\n",
       "      <td>0.263862</td>\n",
       "      <td>0.267097</td>\n",
       "      <td>0.273994</td>\n",
       "      <td>0.275825</td>\n",
       "      <td>0.278205</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>0.590885</td>\n",
       "      <td>0.606083</td>\n",
       "      <td>0.546757</td>\n",
       "      <td>0.538701</td>\n",
       "      <td>0.519017</td>\n",
       "      <td>0.495824</td>\n",
       "      <td>0.471014</td>\n",
       "      <td>0.456960</td>\n",
       "      <td>0.445028</td>\n",
       "      <td>0.430059</td>\n",
       "      <td>...</td>\n",
       "      <td>0.427710</td>\n",
       "      <td>0.258949</td>\n",
       "      <td>0.390906</td>\n",
       "      <td>0.526479</td>\n",
       "      <td>0.246345</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.342383</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.501470</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>760</th>\n",
       "      <td>0.558415</td>\n",
       "      <td>0.560734</td>\n",
       "      <td>0.510930</td>\n",
       "      <td>0.511449</td>\n",
       "      <td>0.497258</td>\n",
       "      <td>0.460973</td>\n",
       "      <td>0.463110</td>\n",
       "      <td>0.449590</td>\n",
       "      <td>0.437887</td>\n",
       "      <td>0.433767</td>\n",
       "      <td>...</td>\n",
       "      <td>0.258400</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.257820</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.268745</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.409025</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.256294</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942</th>\n",
       "      <td>0.500615</td>\n",
       "      <td>0.518987</td>\n",
       "      <td>0.499517</td>\n",
       "      <td>0.453192</td>\n",
       "      <td>0.466131</td>\n",
       "      <td>0.450659</td>\n",
       "      <td>0.460592</td>\n",
       "      <td>0.445486</td>\n",
       "      <td>0.420096</td>\n",
       "      <td>0.411123</td>\n",
       "      <td>...</td>\n",
       "      <td>0.231697</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.278114</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.234291</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.130593</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.237373</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20 rows × 69 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "strike                 50.0      55.0      60.0      65.0      70.0   \\\n",
       "time_to_expiration                                                     \n",
       "4                   3.000002       NaN       NaN       NaN  2.187505   \n",
       "11                  2.617191       NaN       NaN       NaN  1.500002   \n",
       "18                       NaN       NaN       NaN       NaN       NaN   \n",
       "25                       NaN       NaN  1.551760  1.382816  1.339847   \n",
       "32                  1.843751       NaN       NaN       NaN       NaN   \n",
       "39                       NaN       NaN       NaN       NaN       NaN   \n",
       "60                  1.304691  0.429693  1.127932  1.142580  0.970951   \n",
       "88                  1.052249  0.359381  0.977786  0.405279  0.898929   \n",
       "116                      NaN       NaN       NaN  0.784304  0.758791   \n",
       "151                      NaN  0.815434  0.291023  0.265632  0.712527   \n",
       "179                 0.835209  0.297859  0.566411  0.513677  0.503911   \n",
       "207                      NaN       NaN       NaN  0.676639  0.649418   \n",
       "242                 0.752688  0.718387  0.688846  0.654972  0.628239   \n",
       "298                 0.706058  0.595219  0.646610  0.624027  0.617497   \n",
       "396                 0.665409  0.667057  0.605839  0.571904  0.556737   \n",
       "487                 0.614933  0.537846  0.516362  0.581608  0.522405   \n",
       "578                 0.606144  0.252693  0.271370  0.512700  0.488653   \n",
       "606                 0.590885  0.606083  0.546757  0.538701  0.519017   \n",
       "760                 0.558415  0.560734  0.510930  0.511449  0.497258   \n",
       "942                 0.500615  0.518987  0.499517  0.453192  0.466131   \n",
       "\n",
       "strike                 75.0      80.0      85.0      90.0      95.0   ...  \\\n",
       "time_to_expiration                                                    ...   \n",
       "4                        NaN       NaN       NaN  1.625002  1.656252  ...   \n",
       "11                       NaN       NaN  1.765626  1.503909  1.332035  ...   \n",
       "18                       NaN       NaN       NaN  1.164067  1.136723  ...   \n",
       "25                  1.313480  1.189943  1.103520  1.115727  0.956058  ...   \n",
       "32                       NaN       NaN       NaN       NaN       NaN  ...   \n",
       "39                       NaN       NaN       NaN  0.818361       NaN  ...   \n",
       "60                  0.998538  0.820070  0.802248  0.741214  0.715091  ...   \n",
       "88                  0.796389  0.754519  0.707278  0.666629  0.649295  ...   \n",
       "116                 0.705447  0.687259  0.662357  0.630863  0.596684  ...   \n",
       "151                 0.677493  0.253914  0.617863  0.591984  0.564580  ...   \n",
       "179                 0.651188  0.626469  0.597294  0.571354  0.544682  ...   \n",
       "207                 0.624882  0.597904  0.572270  0.549748  0.526372  ...   \n",
       "242                 0.604374  0.577641  0.554448  0.531011  0.508916  ...   \n",
       "298                 0.590885  0.566533  0.540349  0.518193  0.499669  ...   \n",
       "396                 0.531743  0.552861  0.492925  0.475591  0.488256  ...   \n",
       "487                 0.402594  0.486883  0.191292  0.482397  0.465032  ...   \n",
       "578                 0.520604  0.384741  0.423834  0.464788  0.449987  ...   \n",
       "606                 0.495824  0.471014  0.456960  0.445028  0.430059  ...   \n",
       "760                 0.460973  0.463110  0.449590  0.437887  0.433767  ...   \n",
       "942                 0.450659  0.460592  0.445486  0.420096  0.411123  ...   \n",
       "\n",
       "strike                 270.0     275.0     280.0     285.0     290.0  \\\n",
       "time_to_expiration                                                     \n",
       "4                        NaN       NaN       NaN       NaN       NaN   \n",
       "11                       NaN       NaN       NaN       NaN       NaN   \n",
       "18                       NaN       NaN       NaN       NaN       NaN   \n",
       "25                  1.897311       NaN  1.838503       NaN  2.093081   \n",
       "32                       NaN       NaN       NaN       NaN       NaN   \n",
       "39                       NaN       NaN       NaN       NaN       NaN   \n",
       "60                  0.827306       NaN  1.213751       NaN       NaN   \n",
       "88                       NaN       NaN       NaN       NaN       NaN   \n",
       "116                 0.695776       NaN  0.893071       NaN  0.961873   \n",
       "151                 0.297859  0.824041  0.292488  0.277351  0.285163   \n",
       "179                 0.235359  0.238289  0.246101  0.125009  0.261726   \n",
       "207                 0.305061  0.231453  0.320563  0.646933  0.657828   \n",
       "242                 0.549214  0.540517  0.459539  0.603214  0.438055   \n",
       "298                 0.548207  0.619556  0.291969  0.501744  0.263923   \n",
       "396                 0.258827  0.240486  0.506795  0.228035  0.512624   \n",
       "487                 0.231880       NaN  0.282844       NaN  0.274055   \n",
       "578                 0.250801  0.259895  0.261177  0.262153  0.263862   \n",
       "606                 0.427710  0.258949  0.390906  0.526479  0.246345   \n",
       "760                 0.258400       NaN  0.257820       NaN  0.268745   \n",
       "942                 0.231697       NaN  0.278114       NaN  0.234291   \n",
       "\n",
       "strike                 295.0     300.0     305.0     310.0     320.0  \n",
       "time_to_expiration                                                    \n",
       "4                        NaN       NaN       NaN       NaN       NaN  \n",
       "11                       NaN       NaN       NaN       NaN       NaN  \n",
       "18                       NaN       NaN       NaN       NaN       NaN  \n",
       "25                       NaN  1.482548       NaN       NaN       NaN  \n",
       "32                       NaN       NaN       NaN       NaN       NaN  \n",
       "39                       NaN       NaN       NaN       NaN       NaN  \n",
       "60                       NaN       NaN       NaN       NaN       NaN  \n",
       "88                       NaN       NaN       NaN       NaN       NaN  \n",
       "116                      NaN  0.466070       NaN       NaN       NaN  \n",
       "151                 0.293952       NaN       NaN       NaN       NaN  \n",
       "179                      NaN  0.269539       NaN       NaN       NaN  \n",
       "207                 0.251961       NaN       NaN       NaN       NaN  \n",
       "242                      NaN  0.327827       NaN  0.344672  0.355963  \n",
       "298                      NaN  0.278328       NaN  0.291023       NaN  \n",
       "396                      NaN  0.364356       NaN  0.590962  0.322852  \n",
       "487                      NaN  0.421408       NaN  0.242195       NaN  \n",
       "578                 0.267097  0.273994  0.275825  0.278205       NaN  \n",
       "606                      NaN  0.342383       NaN  0.501470       NaN  \n",
       "760                      NaN  0.409025       NaN  0.256294       NaN  \n",
       "942                      NaN  0.130593       NaN  0.237373       NaN  \n",
       "\n",
       "[20 rows x 69 columns]"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mb_iv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e748b09-f410-468c-9857-53ce765f40e5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "b830448a-5944-4d10-8dbb-8ecb7ff72bcf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "strike                 50.0      55.0      60.0      65.0      70.0   \\\n",
      "time_to_expiration                                                     \n",
      "4                   3.000002       NaN       NaN       NaN  2.187505   \n",
      "11                  2.617191       NaN       NaN       NaN  1.500002   \n",
      "32                  1.843751       NaN       NaN       NaN       NaN   \n",
      "60                  1.304691  0.429693  1.127932  1.142580  0.970951   \n",
      "88                  1.052249  0.359381  0.977786  0.405279  0.898929   \n",
      "179                 0.835209  0.297859  0.566411  0.513677  0.503911   \n",
      "298                 0.706058  0.595219  0.646610  0.624027  0.617497   \n",
      "396                 0.665409  0.667057  0.605839  0.571904  0.556737   \n",
      "578                 0.606144  0.252693  0.271370  0.512700  0.488653   \n",
      "760                 0.558415  0.560734  0.510930  0.511449  0.497258   \n",
      "942                 0.500615  0.518987  0.499517  0.453192  0.466131   \n",
      "\n",
      "strike                 75.0      80.0      85.0      90.0      95.0   ...  \\\n",
      "time_to_expiration                                                    ...   \n",
      "4                        NaN       NaN       NaN  1.625002  1.656252  ...   \n",
      "11                       NaN       NaN  1.765626  1.503909  1.332035  ...   \n",
      "32                       NaN       NaN       NaN       NaN       NaN  ...   \n",
      "60                  0.998538  0.820070  0.802248  0.741214  0.715091  ...   \n",
      "88                  0.796389  0.754519  0.707278  0.666629  0.649295  ...   \n",
      "179                 0.651188  0.626469  0.597294  0.571354  0.544682  ...   \n",
      "298                 0.590885  0.566533  0.540349  0.518193  0.499669  ...   \n",
      "396                 0.531743  0.552861  0.492925  0.475591  0.488256  ...   \n",
      "578                 0.520604  0.384741  0.423834  0.464788  0.449987  ...   \n",
      "760                 0.460973  0.463110  0.449590  0.437887  0.433767  ...   \n",
      "942                 0.450659  0.460592  0.445486  0.420096  0.411123  ...   \n",
      "\n",
      "strike                 270.0     275.0     280.0     285.0     290.0  \\\n",
      "time_to_expiration                                                     \n",
      "4                        NaN       NaN       NaN       NaN       NaN   \n",
      "11                       NaN       NaN       NaN       NaN       NaN   \n",
      "32                       NaN       NaN       NaN       NaN       NaN   \n",
      "60                  0.827306       NaN  1.213751       NaN       NaN   \n",
      "88                       NaN       NaN       NaN       NaN       NaN   \n",
      "179                 0.235359  0.238289  0.246101  0.125009  0.261726   \n",
      "298                 0.548207  0.619556  0.291969  0.501744  0.263923   \n",
      "396                 0.258827  0.240486  0.506795  0.228035  0.512624   \n",
      "578                 0.250801  0.259895  0.261177  0.262153  0.263862   \n",
      "760                 0.258400       NaN  0.257820       NaN  0.268745   \n",
      "942                 0.231697       NaN  0.278114       NaN  0.234291   \n",
      "\n",
      "strike                 295.0     300.0     305.0     310.0     320.0  \n",
      "time_to_expiration                                                    \n",
      "4                        NaN       NaN       NaN       NaN       NaN  \n",
      "11                       NaN       NaN       NaN       NaN       NaN  \n",
      "32                       NaN       NaN       NaN       NaN       NaN  \n",
      "60                       NaN       NaN       NaN       NaN       NaN  \n",
      "88                       NaN       NaN       NaN       NaN       NaN  \n",
      "179                      NaN  0.269539       NaN       NaN       NaN  \n",
      "298                      NaN  0.278328       NaN  0.291023       NaN  \n",
      "396                      NaN  0.364356       NaN  0.590962  0.322852  \n",
      "578                 0.267097  0.273994  0.275825  0.278205       NaN  \n",
      "760                      NaN  0.409025       NaN  0.256294       NaN  \n",
      "942                      NaN  0.130593       NaN  0.237373       NaN  \n",
      "\n",
      "[11 rows x 69 columns]\n"
     ]
    }
   ],
   "source": [
    "# Take a copy of mb_iv\n",
    "mb_iv_std = mb_iv.copy()\n",
    "\n",
    "# Filter rows based on time_to_expiration\n",
    "desired_tenors = [4, 11, 32, 60, 88, 179, 298, 396, 578, 760, 942]\n",
    "mb_iv_std = mb_iv_std[mb_iv_std.index.isin(desired_tenors)]\n",
    "\n",
    "print(mb_iv_std)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "896593a7-4436-451d-a24d-f7a3deedfc7a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>strike</th>\n",
       "      <th>120.0</th>\n",
       "      <th>125.0</th>\n",
       "      <th>130.0</th>\n",
       "      <th>135.0</th>\n",
       "      <th>140.0</th>\n",
       "      <th>145.0</th>\n",
       "      <th>150.0</th>\n",
       "      <th>155.0</th>\n",
       "      <th>160.0</th>\n",
       "      <th>165.0</th>\n",
       "      <th>170.0</th>\n",
       "      <th>175.0</th>\n",
       "      <th>180.0</th>\n",
       "      <th>185.0</th>\n",
       "      <th>190.0</th>\n",
       "      <th>195.0</th>\n",
       "      <th>200.0</th>\n",
       "      <th>205.0</th>\n",
       "      <th>210.0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time_to_expiration</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.150392</td>\n",
       "      <td>1.047854</td>\n",
       "      <td>0.996097</td>\n",
       "      <td>1.130618</td>\n",
       "      <td>0.741214</td>\n",
       "      <td>0.730960</td>\n",
       "      <td>0.547856</td>\n",
       "      <td>0.492681</td>\n",
       "      <td>0.417730</td>\n",
       "      <td>0.318366</td>\n",
       "      <td>0.234505</td>\n",
       "      <td>0.184701</td>\n",
       "      <td>0.173836</td>\n",
       "      <td>0.268806</td>\n",
       "      <td>0.316901</td>\n",
       "      <td>0.510503</td>\n",
       "      <td>0.555913</td>\n",
       "      <td>0.503911</td>\n",
       "      <td>0.872563</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1.155031</td>\n",
       "      <td>0.795412</td>\n",
       "      <td>0.713382</td>\n",
       "      <td>0.644535</td>\n",
       "      <td>0.607426</td>\n",
       "      <td>0.518560</td>\n",
       "      <td>0.453130</td>\n",
       "      <td>0.398688</td>\n",
       "      <td>0.332770</td>\n",
       "      <td>0.267708</td>\n",
       "      <td>0.233772</td>\n",
       "      <td>0.185860</td>\n",
       "      <td>0.161019</td>\n",
       "      <td>0.234383</td>\n",
       "      <td>0.314704</td>\n",
       "      <td>0.448248</td>\n",
       "      <td>0.449835</td>\n",
       "      <td>0.533452</td>\n",
       "      <td>0.491216</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>0.503911</td>\n",
       "      <td>0.472662</td>\n",
       "      <td>0.543950</td>\n",
       "      <td>0.482793</td>\n",
       "      <td>0.495000</td>\n",
       "      <td>0.466314</td>\n",
       "      <td>0.418829</td>\n",
       "      <td>0.322822</td>\n",
       "      <td>0.283699</td>\n",
       "      <td>0.251533</td>\n",
       "      <td>0.234413</td>\n",
       "      <td>0.197030</td>\n",
       "      <td>0.177834</td>\n",
       "      <td>0.171761</td>\n",
       "      <td>0.245369</td>\n",
       "      <td>0.252632</td>\n",
       "      <td>0.298225</td>\n",
       "      <td>0.218758</td>\n",
       "      <td>0.240242</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>0.539800</td>\n",
       "      <td>0.489324</td>\n",
       "      <td>0.454351</td>\n",
       "      <td>0.430670</td>\n",
       "      <td>0.429571</td>\n",
       "      <td>0.359320</td>\n",
       "      <td>0.344764</td>\n",
       "      <td>0.299751</td>\n",
       "      <td>0.274971</td>\n",
       "      <td>0.248726</td>\n",
       "      <td>0.225350</td>\n",
       "      <td>0.202401</td>\n",
       "      <td>0.181405</td>\n",
       "      <td>0.160653</td>\n",
       "      <td>0.191811</td>\n",
       "      <td>0.215584</td>\n",
       "      <td>0.221382</td>\n",
       "      <td>0.241768</td>\n",
       "      <td>0.282966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>0.484380</td>\n",
       "      <td>0.455572</td>\n",
       "      <td>0.468572</td>\n",
       "      <td>0.440008</td>\n",
       "      <td>0.386298</td>\n",
       "      <td>0.366583</td>\n",
       "      <td>0.334418</td>\n",
       "      <td>0.305854</td>\n",
       "      <td>0.286537</td>\n",
       "      <td>0.266243</td>\n",
       "      <td>0.246498</td>\n",
       "      <td>0.227181</td>\n",
       "      <td>0.208840</td>\n",
       "      <td>0.190651</td>\n",
       "      <td>0.197335</td>\n",
       "      <td>0.198677</td>\n",
       "      <td>0.194100</td>\n",
       "      <td>0.222847</td>\n",
       "      <td>0.251350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>0.431280</td>\n",
       "      <td>0.424963</td>\n",
       "      <td>0.404974</td>\n",
       "      <td>0.390265</td>\n",
       "      <td>0.362128</td>\n",
       "      <td>0.347480</td>\n",
       "      <td>0.328910</td>\n",
       "      <td>0.310096</td>\n",
       "      <td>0.306373</td>\n",
       "      <td>0.294685</td>\n",
       "      <td>0.275550</td>\n",
       "      <td>0.253486</td>\n",
       "      <td>0.236610</td>\n",
       "      <td>0.222710</td>\n",
       "      <td>0.217964</td>\n",
       "      <td>0.209481</td>\n",
       "      <td>0.197823</td>\n",
       "      <td>0.221504</td>\n",
       "      <td>0.223244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>0.409826</td>\n",
       "      <td>0.407263</td>\n",
       "      <td>0.384772</td>\n",
       "      <td>0.375647</td>\n",
       "      <td>0.352393</td>\n",
       "      <td>0.342994</td>\n",
       "      <td>0.325263</td>\n",
       "      <td>0.323783</td>\n",
       "      <td>0.299308</td>\n",
       "      <td>0.297508</td>\n",
       "      <td>0.277153</td>\n",
       "      <td>0.279533</td>\n",
       "      <td>0.264824</td>\n",
       "      <td>0.247505</td>\n",
       "      <td>0.229775</td>\n",
       "      <td>0.232674</td>\n",
       "      <td>0.218620</td>\n",
       "      <td>0.214745</td>\n",
       "      <td>0.203560</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>0.408117</td>\n",
       "      <td>0.389441</td>\n",
       "      <td>0.378455</td>\n",
       "      <td>0.361899</td>\n",
       "      <td>0.350272</td>\n",
       "      <td>0.337882</td>\n",
       "      <td>0.323630</td>\n",
       "      <td>0.321738</td>\n",
       "      <td>0.305488</td>\n",
       "      <td>0.299949</td>\n",
       "      <td>0.290115</td>\n",
       "      <td>0.275291</td>\n",
       "      <td>0.264923</td>\n",
       "      <td>0.251839</td>\n",
       "      <td>0.255073</td>\n",
       "      <td>0.231514</td>\n",
       "      <td>0.222954</td>\n",
       "      <td>0.210335</td>\n",
       "      <td>0.220268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578</th>\n",
       "      <td>0.381079</td>\n",
       "      <td>0.378699</td>\n",
       "      <td>0.367850</td>\n",
       "      <td>0.352958</td>\n",
       "      <td>0.345801</td>\n",
       "      <td>0.339087</td>\n",
       "      <td>0.326179</td>\n",
       "      <td>0.321952</td>\n",
       "      <td>0.316840</td>\n",
       "      <td>0.310371</td>\n",
       "      <td>0.298271</td>\n",
       "      <td>0.293479</td>\n",
       "      <td>0.284736</td>\n",
       "      <td>0.271827</td>\n",
       "      <td>0.258217</td>\n",
       "      <td>0.252006</td>\n",
       "      <td>0.243591</td>\n",
       "      <td>0.242096</td>\n",
       "      <td>0.230225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>760</th>\n",
       "      <td>0.371375</td>\n",
       "      <td>0.367789</td>\n",
       "      <td>0.353392</td>\n",
       "      <td>0.347403</td>\n",
       "      <td>0.337157</td>\n",
       "      <td>0.330771</td>\n",
       "      <td>0.322929</td>\n",
       "      <td>0.315246</td>\n",
       "      <td>0.307151</td>\n",
       "      <td>0.301475</td>\n",
       "      <td>0.294067</td>\n",
       "      <td>0.290031</td>\n",
       "      <td>0.273216</td>\n",
       "      <td>0.271461</td>\n",
       "      <td>0.271362</td>\n",
       "      <td>0.264930</td>\n",
       "      <td>0.255760</td>\n",
       "      <td>0.245300</td>\n",
       "      <td>0.235222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942</th>\n",
       "      <td>0.361052</td>\n",
       "      <td>0.352958</td>\n",
       "      <td>0.346717</td>\n",
       "      <td>0.335380</td>\n",
       "      <td>0.332107</td>\n",
       "      <td>0.324149</td>\n",
       "      <td>0.316741</td>\n",
       "      <td>0.307250</td>\n",
       "      <td>0.301177</td>\n",
       "      <td>0.297325</td>\n",
       "      <td>0.288192</td>\n",
       "      <td>0.287208</td>\n",
       "      <td>0.276176</td>\n",
       "      <td>0.270828</td>\n",
       "      <td>0.266380</td>\n",
       "      <td>0.257263</td>\n",
       "      <td>0.255249</td>\n",
       "      <td>0.246010</td>\n",
       "      <td>0.242836</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "strike                 120.0     125.0     130.0     135.0     140.0  \\\n",
       "time_to_expiration                                                     \n",
       "4                   1.150392  1.047854  0.996097  1.130618  0.741214   \n",
       "11                  1.155031  0.795412  0.713382  0.644535  0.607426   \n",
       "32                  0.503911  0.472662  0.543950  0.482793  0.495000   \n",
       "60                  0.539800  0.489324  0.454351  0.430670  0.429571   \n",
       "88                  0.484380  0.455572  0.468572  0.440008  0.386298   \n",
       "179                 0.431280  0.424963  0.404974  0.390265  0.362128   \n",
       "298                 0.409826  0.407263  0.384772  0.375647  0.352393   \n",
       "396                 0.408117  0.389441  0.378455  0.361899  0.350272   \n",
       "578                 0.381079  0.378699  0.367850  0.352958  0.345801   \n",
       "760                 0.371375  0.367789  0.353392  0.347403  0.337157   \n",
       "942                 0.361052  0.352958  0.346717  0.335380  0.332107   \n",
       "\n",
       "strike                 145.0     150.0     155.0     160.0     165.0  \\\n",
       "time_to_expiration                                                     \n",
       "4                   0.730960  0.547856  0.492681  0.417730  0.318366   \n",
       "11                  0.518560  0.453130  0.398688  0.332770  0.267708   \n",
       "32                  0.466314  0.418829  0.322822  0.283699  0.251533   \n",
       "60                  0.359320  0.344764  0.299751  0.274971  0.248726   \n",
       "88                  0.366583  0.334418  0.305854  0.286537  0.266243   \n",
       "179                 0.347480  0.328910  0.310096  0.306373  0.294685   \n",
       "298                 0.342994  0.325263  0.323783  0.299308  0.297508   \n",
       "396                 0.337882  0.323630  0.321738  0.305488  0.299949   \n",
       "578                 0.339087  0.326179  0.321952  0.316840  0.310371   \n",
       "760                 0.330771  0.322929  0.315246  0.307151  0.301475   \n",
       "942                 0.324149  0.316741  0.307250  0.301177  0.297325   \n",
       "\n",
       "strike                 170.0     175.0     180.0     185.0     190.0  \\\n",
       "time_to_expiration                                                     \n",
       "4                   0.234505  0.184701  0.173836  0.268806  0.316901   \n",
       "11                  0.233772  0.185860  0.161019  0.234383  0.314704   \n",
       "32                  0.234413  0.197030  0.177834  0.171761  0.245369   \n",
       "60                  0.225350  0.202401  0.181405  0.160653  0.191811   \n",
       "88                  0.246498  0.227181  0.208840  0.190651  0.197335   \n",
       "179                 0.275550  0.253486  0.236610  0.222710  0.217964   \n",
       "298                 0.277153  0.279533  0.264824  0.247505  0.229775   \n",
       "396                 0.290115  0.275291  0.264923  0.251839  0.255073   \n",
       "578                 0.298271  0.293479  0.284736  0.271827  0.258217   \n",
       "760                 0.294067  0.290031  0.273216  0.271461  0.271362   \n",
       "942                 0.288192  0.287208  0.276176  0.270828  0.266380   \n",
       "\n",
       "strike                 195.0     200.0     205.0     210.0  \n",
       "time_to_expiration                                          \n",
       "4                   0.510503  0.555913  0.503911  0.872563  \n",
       "11                  0.448248  0.449835  0.533452  0.491216  \n",
       "32                  0.252632  0.298225  0.218758  0.240242  \n",
       "60                  0.215584  0.221382  0.241768  0.282966  \n",
       "88                  0.198677  0.194100  0.222847  0.251350  \n",
       "179                 0.209481  0.197823  0.221504  0.223244  \n",
       "298                 0.232674  0.218620  0.214745  0.203560  \n",
       "396                 0.231514  0.222954  0.210335  0.220268  \n",
       "578                 0.252006  0.243591  0.242096  0.230225  \n",
       "760                 0.264930  0.255760  0.245300  0.235222  \n",
       "942                 0.257263  0.255249  0.246010  0.242836  "
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Specify the desired strike values (19 Stike points)\n",
    "desired_strikes = [120, 125, 130, 135,\n",
    "                   140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200, 205, 210]\n",
    "\n",
    "# Filter columns based on desired_strikes\n",
    "mb_iv_std = mb_iv_std[desired_strikes]\n",
    "\n",
    "mb_iv_std\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "056e0023-781c-42de-a779-d84bcbc91975",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>strike</th>\n",
       "      <th>100.0</th>\n",
       "      <th>105.0</th>\n",
       "      <th>110.0</th>\n",
       "      <th>115.0</th>\n",
       "      <th>120.0</th>\n",
       "      <th>125.0</th>\n",
       "      <th>130.0</th>\n",
       "      <th>135.0</th>\n",
       "      <th>140.0</th>\n",
       "      <th>145.0</th>\n",
       "      <th>...</th>\n",
       "      <th>205.0</th>\n",
       "      <th>210.0</th>\n",
       "      <th>215.0</th>\n",
       "      <th>220.0</th>\n",
       "      <th>225.0</th>\n",
       "      <th>230.0</th>\n",
       "      <th>235.0</th>\n",
       "      <th>240.0</th>\n",
       "      <th>245.0</th>\n",
       "      <th>250.0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time_to_expiration</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2.123050</td>\n",
       "      <td>1.250004</td>\n",
       "      <td>1.817387</td>\n",
       "      <td>1.300785</td>\n",
       "      <td>1.150392</td>\n",
       "      <td>1.047854</td>\n",
       "      <td>0.996097</td>\n",
       "      <td>1.130618</td>\n",
       "      <td>0.741214</td>\n",
       "      <td>0.730960</td>\n",
       "      <td>...</td>\n",
       "      <td>0.503911</td>\n",
       "      <td>0.872563</td>\n",
       "      <td>0.531255</td>\n",
       "      <td>0.946293</td>\n",
       "      <td>0.640629</td>\n",
       "      <td>0.687503</td>\n",
       "      <td>1.148388</td>\n",
       "      <td>0.781252</td>\n",
       "      <td>0.693047</td>\n",
       "      <td>1.326661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1.316410</td>\n",
       "      <td>1.132817</td>\n",
       "      <td>1.132817</td>\n",
       "      <td>0.949219</td>\n",
       "      <td>1.155031</td>\n",
       "      <td>0.795412</td>\n",
       "      <td>0.713382</td>\n",
       "      <td>0.644535</td>\n",
       "      <td>0.607426</td>\n",
       "      <td>0.518560</td>\n",
       "      <td>...</td>\n",
       "      <td>0.533452</td>\n",
       "      <td>0.491216</td>\n",
       "      <td>0.679080</td>\n",
       "      <td>0.537114</td>\n",
       "      <td>0.544926</td>\n",
       "      <td>0.621098</td>\n",
       "      <td>1.036550</td>\n",
       "      <td>0.788535</td>\n",
       "      <td>0.562504</td>\n",
       "      <td>0.593754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>0.755862</td>\n",
       "      <td>0.648441</td>\n",
       "      <td>0.716311</td>\n",
       "      <td>0.681888</td>\n",
       "      <td>0.503911</td>\n",
       "      <td>0.472662</td>\n",
       "      <td>0.543950</td>\n",
       "      <td>0.482793</td>\n",
       "      <td>0.495000</td>\n",
       "      <td>0.466314</td>\n",
       "      <td>...</td>\n",
       "      <td>0.218758</td>\n",
       "      <td>0.240242</td>\n",
       "      <td>0.697599</td>\n",
       "      <td>0.367194</td>\n",
       "      <td>0.396979</td>\n",
       "      <td>0.480286</td>\n",
       "      <td>0.739773</td>\n",
       "      <td>0.748971</td>\n",
       "      <td>0.607914</td>\n",
       "      <td>0.824465</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>0.673099</td>\n",
       "      <td>0.636112</td>\n",
       "      <td>0.602543</td>\n",
       "      <td>0.564213</td>\n",
       "      <td>0.539800</td>\n",
       "      <td>0.489324</td>\n",
       "      <td>0.454351</td>\n",
       "      <td>0.430670</td>\n",
       "      <td>0.429571</td>\n",
       "      <td>0.359320</td>\n",
       "      <td>...</td>\n",
       "      <td>0.241768</td>\n",
       "      <td>0.282966</td>\n",
       "      <td>0.297859</td>\n",
       "      <td>1.060734</td>\n",
       "      <td>1.140021</td>\n",
       "      <td>0.356574</td>\n",
       "      <td>0.434454</td>\n",
       "      <td>0.552922</td>\n",
       "      <td>1.233190</td>\n",
       "      <td>0.509404</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>0.613773</td>\n",
       "      <td>0.233406</td>\n",
       "      <td>0.548100</td>\n",
       "      <td>0.515752</td>\n",
       "      <td>0.484380</td>\n",
       "      <td>0.455572</td>\n",
       "      <td>0.468572</td>\n",
       "      <td>0.440008</td>\n",
       "      <td>0.386298</td>\n",
       "      <td>0.366583</td>\n",
       "      <td>...</td>\n",
       "      <td>0.222847</td>\n",
       "      <td>0.251350</td>\n",
       "      <td>0.195809</td>\n",
       "      <td>0.282356</td>\n",
       "      <td>0.211922</td>\n",
       "      <td>0.216805</td>\n",
       "      <td>0.232430</td>\n",
       "      <td>0.238289</td>\n",
       "      <td>0.251961</td>\n",
       "      <td>0.296882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>0.420904</td>\n",
       "      <td>0.499395</td>\n",
       "      <td>0.473760</td>\n",
       "      <td>0.186165</td>\n",
       "      <td>0.431280</td>\n",
       "      <td>0.424963</td>\n",
       "      <td>0.404974</td>\n",
       "      <td>0.390265</td>\n",
       "      <td>0.362128</td>\n",
       "      <td>0.347480</td>\n",
       "      <td>...</td>\n",
       "      <td>0.221504</td>\n",
       "      <td>0.223244</td>\n",
       "      <td>0.210762</td>\n",
       "      <td>0.207405</td>\n",
       "      <td>0.204842</td>\n",
       "      <td>0.204842</td>\n",
       "      <td>0.205574</td>\n",
       "      <td>0.208260</td>\n",
       "      <td>0.209481</td>\n",
       "      <td>0.214852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>0.469854</td>\n",
       "      <td>0.458502</td>\n",
       "      <td>0.439428</td>\n",
       "      <td>0.429144</td>\n",
       "      <td>0.409826</td>\n",
       "      <td>0.407263</td>\n",
       "      <td>0.384772</td>\n",
       "      <td>0.375647</td>\n",
       "      <td>0.352393</td>\n",
       "      <td>0.342994</td>\n",
       "      <td>...</td>\n",
       "      <td>0.214745</td>\n",
       "      <td>0.203560</td>\n",
       "      <td>0.375952</td>\n",
       "      <td>0.248054</td>\n",
       "      <td>0.294853</td>\n",
       "      <td>0.228157</td>\n",
       "      <td>0.627875</td>\n",
       "      <td>0.634421</td>\n",
       "      <td>0.244850</td>\n",
       "      <td>0.269325</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>0.468908</td>\n",
       "      <td>0.444067</td>\n",
       "      <td>0.421087</td>\n",
       "      <td>0.430334</td>\n",
       "      <td>0.408117</td>\n",
       "      <td>0.389441</td>\n",
       "      <td>0.378455</td>\n",
       "      <td>0.361899</td>\n",
       "      <td>0.350272</td>\n",
       "      <td>0.337882</td>\n",
       "      <td>...</td>\n",
       "      <td>0.210335</td>\n",
       "      <td>0.220268</td>\n",
       "      <td>0.213585</td>\n",
       "      <td>0.215248</td>\n",
       "      <td>0.239037</td>\n",
       "      <td>0.241386</td>\n",
       "      <td>0.225105</td>\n",
       "      <td>0.230965</td>\n",
       "      <td>0.235847</td>\n",
       "      <td>0.247841</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578</th>\n",
       "      <td>0.436514</td>\n",
       "      <td>0.428900</td>\n",
       "      <td>0.414175</td>\n",
       "      <td>0.404364</td>\n",
       "      <td>0.381079</td>\n",
       "      <td>0.378699</td>\n",
       "      <td>0.367850</td>\n",
       "      <td>0.352958</td>\n",
       "      <td>0.345801</td>\n",
       "      <td>0.339087</td>\n",
       "      <td>...</td>\n",
       "      <td>0.242096</td>\n",
       "      <td>0.230225</td>\n",
       "      <td>0.217247</td>\n",
       "      <td>0.207421</td>\n",
       "      <td>0.257088</td>\n",
       "      <td>0.268013</td>\n",
       "      <td>0.264869</td>\n",
       "      <td>0.260261</td>\n",
       "      <td>0.263862</td>\n",
       "      <td>0.260780</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>760</th>\n",
       "      <td>0.425695</td>\n",
       "      <td>0.408011</td>\n",
       "      <td>0.391089</td>\n",
       "      <td>0.385474</td>\n",
       "      <td>0.371375</td>\n",
       "      <td>0.367789</td>\n",
       "      <td>0.353392</td>\n",
       "      <td>0.347403</td>\n",
       "      <td>0.337157</td>\n",
       "      <td>0.330771</td>\n",
       "      <td>...</td>\n",
       "      <td>0.245300</td>\n",
       "      <td>0.235222</td>\n",
       "      <td>0.238808</td>\n",
       "      <td>0.220200</td>\n",
       "      <td>0.227715</td>\n",
       "      <td>0.283226</td>\n",
       "      <td>0.242752</td>\n",
       "      <td>0.219719</td>\n",
       "      <td>0.282356</td>\n",
       "      <td>0.222382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942</th>\n",
       "      <td>0.392966</td>\n",
       "      <td>0.374869</td>\n",
       "      <td>0.381827</td>\n",
       "      <td>0.371451</td>\n",
       "      <td>0.361052</td>\n",
       "      <td>0.352958</td>\n",
       "      <td>0.346717</td>\n",
       "      <td>0.335380</td>\n",
       "      <td>0.332107</td>\n",
       "      <td>0.324149</td>\n",
       "      <td>...</td>\n",
       "      <td>0.246010</td>\n",
       "      <td>0.242836</td>\n",
       "      <td>0.242477</td>\n",
       "      <td>0.235741</td>\n",
       "      <td>0.232780</td>\n",
       "      <td>0.223976</td>\n",
       "      <td>0.222534</td>\n",
       "      <td>0.221993</td>\n",
       "      <td>0.218239</td>\n",
       "      <td>0.222618</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>11 rows × 31 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "strike                 100.0     105.0     110.0     115.0     120.0  \\\n",
       "time_to_expiration                                                     \n",
       "4                   2.123050  1.250004  1.817387  1.300785  1.150392   \n",
       "11                  1.316410  1.132817  1.132817  0.949219  1.155031   \n",
       "32                  0.755862  0.648441  0.716311  0.681888  0.503911   \n",
       "60                  0.673099  0.636112  0.602543  0.564213  0.539800   \n",
       "88                  0.613773  0.233406  0.548100  0.515752  0.484380   \n",
       "179                 0.420904  0.499395  0.473760  0.186165  0.431280   \n",
       "298                 0.469854  0.458502  0.439428  0.429144  0.409826   \n",
       "396                 0.468908  0.444067  0.421087  0.430334  0.408117   \n",
       "578                 0.436514  0.428900  0.414175  0.404364  0.381079   \n",
       "760                 0.425695  0.408011  0.391089  0.385474  0.371375   \n",
       "942                 0.392966  0.374869  0.381827  0.371451  0.361052   \n",
       "\n",
       "strike                 125.0     130.0     135.0     140.0     145.0  ...  \\\n",
       "time_to_expiration                                                    ...   \n",
       "4                   1.047854  0.996097  1.130618  0.741214  0.730960  ...   \n",
       "11                  0.795412  0.713382  0.644535  0.607426  0.518560  ...   \n",
       "32                  0.472662  0.543950  0.482793  0.495000  0.466314  ...   \n",
       "60                  0.489324  0.454351  0.430670  0.429571  0.359320  ...   \n",
       "88                  0.455572  0.468572  0.440008  0.386298  0.366583  ...   \n",
       "179                 0.424963  0.404974  0.390265  0.362128  0.347480  ...   \n",
       "298                 0.407263  0.384772  0.375647  0.352393  0.342994  ...   \n",
       "396                 0.389441  0.378455  0.361899  0.350272  0.337882  ...   \n",
       "578                 0.378699  0.367850  0.352958  0.345801  0.339087  ...   \n",
       "760                 0.367789  0.353392  0.347403  0.337157  0.330771  ...   \n",
       "942                 0.352958  0.346717  0.335380  0.332107  0.324149  ...   \n",
       "\n",
       "strike                 205.0     210.0     215.0     220.0     225.0  \\\n",
       "time_to_expiration                                                     \n",
       "4                   0.503911  0.872563  0.531255  0.946293  0.640629   \n",
       "11                  0.533452  0.491216  0.679080  0.537114  0.544926   \n",
       "32                  0.218758  0.240242  0.697599  0.367194  0.396979   \n",
       "60                  0.241768  0.282966  0.297859  1.060734  1.140021   \n",
       "88                  0.222847  0.251350  0.195809  0.282356  0.211922   \n",
       "179                 0.221504  0.223244  0.210762  0.207405  0.204842   \n",
       "298                 0.214745  0.203560  0.375952  0.248054  0.294853   \n",
       "396                 0.210335  0.220268  0.213585  0.215248  0.239037   \n",
       "578                 0.242096  0.230225  0.217247  0.207421  0.257088   \n",
       "760                 0.245300  0.235222  0.238808  0.220200  0.227715   \n",
       "942                 0.246010  0.242836  0.242477  0.235741  0.232780   \n",
       "\n",
       "strike                 230.0     235.0     240.0     245.0     250.0  \n",
       "time_to_expiration                                                    \n",
       "4                   0.687503  1.148388  0.781252  0.693047  1.326661  \n",
       "11                  0.621098  1.036550  0.788535  0.562504  0.593754  \n",
       "32                  0.480286  0.739773  0.748971  0.607914  0.824465  \n",
       "60                  0.356574  0.434454  0.552922  1.233190  0.509404  \n",
       "88                  0.216805  0.232430  0.238289  0.251961  0.296882  \n",
       "179                 0.204842  0.205574  0.208260  0.209481  0.214852  \n",
       "298                 0.228157  0.627875  0.634421  0.244850  0.269325  \n",
       "396                 0.241386  0.225105  0.230965  0.235847  0.247841  \n",
       "578                 0.268013  0.264869  0.260261  0.263862  0.260780  \n",
       "760                 0.283226  0.242752  0.219719  0.282356  0.222382  \n",
       "942                 0.223976  0.222534  0.221993  0.218239  0.222618  \n",
       "\n",
       "[11 rows x 31 columns]"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Interpolate and then fill remaining NaNs for each row\n",
    "mb_iv_std = mb_iv_std.apply(lambda row: row.interpolate(method='linear').fillna(method='bfill').fillna(method='ffill'), axis=1)\n",
    "mb_iv_std"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "fde10059-66f5-4754-bc58-3b8a07b9c3ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "strike\n",
       "120.0    0\n",
       "125.0    0\n",
       "130.0    0\n",
       "135.0    0\n",
       "140.0    0\n",
       "145.0    0\n",
       "150.0    0\n",
       "155.0    0\n",
       "160.0    0\n",
       "165.0    0\n",
       "170.0    0\n",
       "175.0    0\n",
       "180.0    0\n",
       "185.0    0\n",
       "190.0    0\n",
       "195.0    0\n",
       "200.0    0\n",
       "205.0    0\n",
       "210.0    0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "na_count = mb_iv_std.isna().sum()\n",
    "na_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6d7b2fda-533d-46cc-bc6c-1eae1ac9b34c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "ae49d94f-882c-44da-83b8-53be5433d0c9",
   "metadata": {},
   "source": [
    "#### Preparing Interest Rate Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "30971cd8-8661-42b4-9618-bccc68de3c04",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   US_Treasury_Rates  Yield\n",
      "0                 1m   5.62\n",
      "1                 2m   5.27\n",
      "2                 3m   5.29\n",
      "3                 4m   5.46\n",
      "4                 6m   5.36\n",
      "5                 1y   5.02\n",
      "6                 2y   4.28\n",
      "7                 3y   3.98\n",
      "8                 5y   3.76\n",
      "9                 7y   3.74\n",
      "10               10y   3.70\n",
      "11               20y   4.07\n",
      "12               30y   3.95\n"
     ]
    }
   ],
   "source": [
    "print(mb_interest_rates)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "6f0a8eb5-2b2a-45a0-a5af-2cf5cc9d21b2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      Pillar  Yield\n",
      "Tenor              \n",
      "30        1m   5.62\n",
      "60        2m   5.27\n",
      "90        3m   5.29\n",
      "120       4m   5.46\n",
      "180       6m   5.36\n",
      "365       1y   5.02\n",
      "730       2y   4.28\n",
      "1095      3y   3.98\n",
      "1825      5y   3.76\n",
      "2555      7y   3.74\n",
      "3650     10y   3.70\n",
      "7300     20y   4.07\n",
      "10950    30y   3.95\n"
     ]
    }
   ],
   "source": [
    "# function to convert tenor to number of days\n",
    "def tenor_to_days(tenor):\n",
    "    value = int(tenor[:-1])\n",
    "    if 'm' in tenor:\n",
    "        return value * 30  # approximate a month to 30 days\n",
    "    elif 'y' in tenor:\n",
    "        return value * 365  # approximate a year to 365 days\n",
    "\n",
    "# create Tenor column and set as new index\n",
    "mb_interest_rates['Tenor'] = mb_interest_rates['US_Treasury_Rates'].apply(tenor_to_days)\n",
    "mb_interest_rates.set_index('Tenor', inplace=True)\n",
    "\n",
    "# Renaming the Original Pillar Columns\n",
    "mb_interest_rates.rename(columns={\"US_Treasury_Rates\": \"Pillar\"}, inplace=True)\n",
    "\n",
    "print(mb_interest_rates)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8fc3656-a2cb-406c-85f7-3297e10c6817",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
